Ticket #182: autocompPatch

File autocompPatch, 1.1 KB (added by jurre, 5 years ago)

patch

Line 
1Index: Padre/lib/Padre/Document.pm
2===================================================================
3--- Padre/lib/Padre/Document.pm (revision 2100)
4+++ Padre/lib/Padre/Document.pm (working copy)
5@@ -607,17 +607,23 @@
6 
7    # line from beginning to current position
8    my $prefix = $editor->GetTextRange($first, $pos);
9-      $prefix =~ s{^.*?((\w+::)*\w+)$}{$1};
10+   $prefix =~ s{^.*?((\w+::)*\w+)$}{$1};
11    my $last   = $editor->GetLength();
12    my $text   = $editor->GetTextRange(0, $last);
13+   my $pre_text  = $editor->GetTextRange(0, $first+length($prefix));
14+   my $post_text = $editor->GetTextRange($first, $last);
15 
16    my $regex;
17-   eval { $regex = qr{\b($prefix\w*(?:::\w+)*)\b} };
18+   eval { $regex = qr{\b($prefix\w+(?:::\w+)*)\b} };
19    if ($@) {
20        return ("Cannot build regex for '$prefix'");
21    }
22+
23    my %seen;
24-   my @words = grep { ! $seen{$_}++ } sort ($text =~ /$regex/g);
25+   my @words;
26+   push @words ,grep { ! $seen{$_}++ } reverse ($pre_text =~ /$regex/g);
27+   push @words , grep { ! $seen{$_}++ } ($post_text =~ /$regex/g);
28+
29    if (@words > 20) {
30        @words = @words[0..19];
31    }