Kephra

 view release on metacpan or  search on metacpan

lib/Kephra/App/SearchBar.pm  view on Meta::CPAN


sub find_prev {                                                       # key command
    my ($self) = @_;
    $self->_find_prev( $self->editor->GetSelectedText  );
}
sub _find_prev {                                                      # search bar command
    my ($self, $term) = @_;
    my $ed = $self->editor;
    my $wrap = $self->{'wrap'}->GetValue;
    my ($start_pos, $end_pos) = $ed->GetSelection;

    if (defined $term and $term){ $self->{'text'}->SetValue( $term ) }
    else                        { $term = $self->search_term  }

    $ed->SetSelection( $start_pos, $start_pos );
    $ed->SearchAnchor;
    my $pos = $ed->SearchPrev( $self->{'flags'},  $term );
    if ($pos == -1){
        $ed->SetSelection( $ed->GetLength , $ed->GetLength );
        $ed->SearchAnchor();
        $pos = $ed->SearchPrev( $self->{'flags'},  $term ) if $wrap;
        $ed->SetSelection( $start_pos, $end_pos ) if $pos == -1;
    }
    $ed->EnsureCaretVisible;
    $pos > -1;
}

sub find_next {                                                       # key command
    my ($self) = @_;
    $self->_find_next( $self->editor->GetSelectedText  );
}
sub _find_next {
    my ($self, $term) = @_;
    my $ed = $self->editor;
    my $wrap = $self->{'wrap'}->GetValue;
    my ($start_pos, $end_pos) = $ed->GetSelection;

    if (defined $term and $term){ $self->{'text'}->SetValue( $term ) }
    else                        { $term = $self->search_term  }

    $ed->SetSelection( $end_pos, $end_pos );
    $ed->SearchAnchor;
    my $pos = $ed->SearchNext( $self->{'flags'}, $term );
    if ($pos == -1){
        $ed->SetSelection( 0, 0 );
        $ed->SearchAnchor;
        $pos = $ed->SearchNext( $self->{'flags'}, $term ) if $wrap;
        $ed->SetSelection( $start_pos, $end_pos ) if $pos == -1;
    }
    $ed->EnsureCaretVisible;
    ($start_pos, $end_pos) = $ed->GetSelection;
    $pos > -1;
}


sub line_nr_around {
    my ($self) = @_;
    my $line_nr = $self->GetCurrentLine
}

sub update_flags {
    my ($self) = @_;
    $self->{'flags'} = (&Wx::wxSTC_FIND_MATCHCASE * $self->{'case'}->GetValue )
                     | (&Wx::wxSTC_FIND_WHOLEWORD * $self->{'word'}->GetValue )
                     | (&Wx::wxSTC_FIND_WORDSTART * $self->{'start'}->GetValue)
                     | (&Wx::wxSTC_FIND_REGEXP    * $self->{'regex'}->GetValue);
}



1;



( run in 0.859 second using v1.01-cache-2.11-cpan-bbe5e583499 )