Ticket #67: forwards_backwards_completion.diff
| File forwards_backwards_completion.diff, 3.7 KB (added by tsee, 5 years ago) |
|---|
-
lib/Padre/Wx/Menu.pm
50 50 EVT_MENU( $win, $menu->{edit}->Append( wxID_FIND, '' ), \&Padre::Wx::MainWindow::on_find ); 51 51 EVT_MENU( $win, $menu->{edit}->Append( -1, "&Find Again\tF3" ), \&Padre::Wx::MainWindow::on_find_again ); 52 52 EVT_MENU( $win, $menu->{edit}->Append( -1, "&Goto\tCtrl-G" ), \&Padre::Wx::MainWindow::on_goto ); 53 EVT_MENU( $win, $menu->{edit}->Append( -1, "&AutoComp\tCtrl-P" ), \&Padre::Wx::MainWindow::on_autocompletition ); 53 EVT_MENU( $win, $menu->{edit}->Append( -1, "&AutoComp->\tCtrl-N" ), \&Padre::Wx::MainWindow::on_forward_autocompletition ); 54 EVT_MENU( $win, $menu->{edit}->Append( -1, "<-&AutoComp\tCtrl-P" ), \&Padre::Wx::MainWindow::on_backward_autocompletition ); 54 55 EVT_MENU( $win, $menu->{edit}->Append( -1, "Subs\tAlt-S" ), sub { $_[0]->{rightbar}->SetFocus()} ); 55 56 EVT_MENU( $win, $menu->{edit}->Append( -1, "&Comment out block\tCtrl-M" ), \&Padre::Wx::MainWindow::on_comment_out_block ); 56 57 EVT_MENU( $win, $menu->{edit}->Append( -1, "&UnComment block\tCtrl-Shift-M" ), \&Padre::Wx::MainWindow::on_uncomment_block ); -
lib/Padre/Wx/MainWindow.pm
400 400 } 401 401 402 402 403 sub on_autocompletition { 404 my $self = shift; 403 sub on_forward_autocompletition { 404 my $self = shift; 405 406 $self->_autocompletition("forward"); 407 return; 408 } 405 409 406 my $id = $self->{notebook}->GetSelection; 407 my $page = $self->{notebook}->GetPage($id); 408 my $pos = $page->GetCurrentPos; 409 my $line = $page->LineFromPosition($pos); 410 my $first = $page->PositionFromLine($line); 411 my $prefix = $page->GetTextRange($first, $pos); # line from beginning to current position 412 $prefix =~ s{^.*?((\w+::)*\w+)$}{$1}; 413 my $last = $page->GetLength(); 414 my $text = $page->GetTextRange(0, $last); 410 411 sub on_backward_autocompletition { 412 my $self = shift; 413 414 $self->_autocompletition("backward"); 415 return; 416 } 417 418 419 sub _autocompletition { 420 my $self = shift; 421 my $direction = shift; 422 423 my $id = $self->{notebook}->GetSelection; 424 my $page = $self->{notebook}->GetPage($id); 425 my $pos = $page->GetCurrentPos; 426 my $line = $page->LineFromPosition($pos); 427 my $first = $page->PositionFromLine($line); 428 my $prefix = $page->GetTextRange($first, $pos); # line from beginning to current position 429 $prefix =~ s{^.*?((\w+::)*\w+)$}{$1}; 430 my $last = $page->GetLength(); 431 my $pre_text = $page->GetTextRange(0, $first+length($prefix)); 432 my $post_text = $page->GetTextRange($first, $last); 433 415 434 my %seen; 416 my @words = grep { ! $seen{$_}++ } sort ($text =~ m{\b($prefix\w*(?:::\w+)*)\b}g); 417 if (@words > 20) { 418 @words = @words[0..19]; 435 my @words; 436 my $completion_regexp = qr{\b($prefix\w*(?:::\w+)*)\b}; 437 if ($direction eq 'forward') { 438 push @words, grep { ! $seen{$_}++ } ($post_text =~ /$completion_regexp/g); 439 push @words, grep { ! $seen{$_}++ } ($pre_text =~ /$completion_regexp/g); 440 } else { 441 push @words, grep { ! $seen{$_}++ } reverse ($pre_text =~ /$completion_regexp/g); 442 push @words, grep { ! $seen{$_}++ } reverse ($post_text =~ /$completion_regexp/g); 419 443 } 444 445 my $max_words = 20; 446 if (@words > $max_words) { 447 @words = @words[0..$max_words-1]; 448 } 420 449 $page->AutoCompShow(length($prefix), join " ", @words); 421 450 422 451 return; 423 452 } 424 453 454 425 455 sub on_right_click { 426 456 my ($self, $event) = @_; 427 457 #print "right\n";
