If two identical URLs appear on the terminal matcher will happily
show them both when displaying the match-list.  Change it so that
duplicates appearing next to each other are removed.

For example, let’s say the screen shows the following URLs in order:

    ⅰ) https://mina86.com/
    ⅱ) https://google.com/
    ⅲ) http://software.schmorp.de/pkg/rxvt-unicode.html
    ⅳ) https://en.wikipedia.org/wiki/Main_Page
    ⅴ) https://en.wikipedia.org/wiki/Main_Page
    ⅵ) https://google.com/

Matcher will now display:

    0-https://google.com/
    1-https://en.wikipedia.org/wiki/Main_Page
    2-http://software.schmorp.de/pkg/rxvt-unicode.html
    3-https://google.com/
    4-https://mina86.com/

Observe that Wikipedia appears only once while Google appears twice.
Thinking behind leaving Google twice is that there may be a big
distance on screen between url ⅲ and ⅳ and user might expecte to
find Google between ⅰ and ⅲ without realising ther’s another
instance at ⅵ.
---
 src/perl/matcher | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/src/perl/matcher b/src/perl/matcher
index d991d68..17cb1a6 100644
--- a/src/perl/matcher
+++ b/src/perl/matcher
@@ -150,44 +150,43 @@ sub on_action {
 sub matchlist {
    my ($self) = @_;
 
-   $self->{matches} = [];
    my $row = $self->nrow - 1;
-   while ($row >= 0 && @{ $self->{matches} } < 10) {
+   my @matches = ();
+   my $width = 0;
+
+   my $text = '';
+   while ($row >= 0 && @matches < 10) {
       my $line = $self->line ($row);
-      my @matches = $self->find_matches ($row);
+      my @m = $self->find_matches ($row);
+
+      for (sort { $b->[0] <=> $a->[0] or $b->[1] <=> $a->[1] } @m) {
+         next if $_->[4] eq $text;
 
-      for (sort { $b->[0] <=> $a->[0] or $b->[1] <=> $a->[1] } @matches) {
-         push @{ $self->{matches} }, $_;
-         last if @{ $self->{matches} } == 10;
+         $text = $_->[4];
+         my $w = $self->strwidth (scalar(@matches) . '-' . $text);
+         $width = $w if $w > $width;
+
+         push @matches, $_;
+         last if @matches == 10;
       }
 
       $row = $line->beg - 1;
    }
 
-   return unless @{ $self->{matches} };
-
-   my $width = 0;
-
-   my $i = 0;
-   for my $match (@{ $self->{matches} }) {
-      my $text = $match->[4];
-      my $w = $self->strwidth ("$i-$text");
-
-      $width = $w if $w > $width;
-      $i++;
-   }
+   return unless @matches;
 
    $width = $self->ncol - 2 if $width > $self->ncol - 2;
 
-   $self->{overlay} = $self->overlay (0, 0, $width, scalar (@{ 
$self->{matches} }), urxvt::OVERLAY_RSTYLE, 2);
+   $self->{overlay} = $self->overlay (0, 0, $width, scalar (@matches), 
urxvt::OVERLAY_RSTYLE, 2);
    my $i = 0;
-   for my $match (@{ $self->{matches} }) {
+   for my $match (@matches) {
       my $text = $match->[4];
 
       $self->{overlay}->set (0, $i, "$i-$text");
       $i++;
    }
 
+   $self->{matches} = \@matches;
    $self->enable (key_press => \&matchlist_key_press);
 }
 
-- 
2.16.2


_______________________________________________
rxvt-unicode mailing list
[email protected]
http://lists.schmorp.de/mailman/listinfo/rxvt-unicode

Reply via email to