Changeset 3320


Ignore:
Timestamp:
03/13/09 07:52:44 (3 years ago)
Author:
jquelin
Message:

new method current_paragraph()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Wx/Editor.pm

    r3313 r3320  
    843843} 
    844844 
     845 
     846# 
     847# my ($begin, $end) = $self->current_paragraph; 
     848# 
     849# return $begin and $end position of current paragraph. 
     850# 
     851sub current_paragraph { 
     852    my ($editor) = @_; 
     853 
     854    my $curpos = $editor->GetCurrentPos; 
     855    my $lineno = $editor->LineFromPosition($curpos); 
     856 
     857    # check if we're in between paragraphs 
     858    return ($curpos, $curpos) if $editor->GetLine($lineno) =~ /^\s*$/; 
     859 
     860    # find the start of paragraph by searching backwards till we find a 
     861    # line with only whitespace in it. 
     862    my $para1 = $lineno; 
     863    while ( $para1 > 0 ) { 
     864        my $line = $editor->GetLine($para1); 
     865        last if $line =~ /^\s*$/; 
     866        $para1--; 
     867    } 
     868 
     869    # now, find the end of paragraph by searching forwards until we find 
     870    # only white space 
     871    my $lastline = $editor->GetLineCount; 
     872    my $para2 = $lineno; 
     873    while ( $para2 < $lastline ) { 
     874        $para2++; 
     875        my $line = $editor->GetLine($para2); 
     876        last if $line =~ /^\s*$/; 
     877    } 
     878 
     879    # return the position 
     880    my $begin = $editor->PositionFromLine($para1+1); 
     881    my $end   = $editor->PositionFromLine($para2); 
     882    return ($begin, $end); 
     883} 
     884 
    845885sub put_text_to_clipboard { 
    846886    my ( $self, $text ) = @_; 
Note: See TracChangeset for help on using the changeset viewer.