diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-11-27 12:31:16 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-11-27 12:31:16 +0100 |
commit | 218b00727a7d451b1fa3c3a8f5638469d40d723e (patch) | |
tree | d835dc6da9c0594440f7e99eaaabe65e617cf6a0 | |
parent | 903071fe157d2de9991f3d61df41ad38b0868934 (diff) |
Do not assign a new hint to duplicate matches.
Reuse the same one for all of them.
-rw-r--r-- | reselect | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -80,18 +80,31 @@ sub build_overlays { my @matches = find_matches($pattern, $text, $rowmap); @matches = reverse @matches if ($self->{descending}); - my $results = {}; - my $hints = hint_iterator(); + + my $match_hints = {}; + my $results = {}; + my $hints = hint_iterator(); for my $m (@matches) { my ($col, $row, $match) = @$m; - my $hint = $hints->(); + # create a new hint if this match was not seen before + # reuse an existing one otherwise + if (not exists $match_hints->{$match}) { + $match_hints->{$match} = $hints->(); + } + my $hint = $match_hints->{$match}; + + if (not exists $results->{$hint}) { + $results->{$hint} = { match => $match, labels => [] }; + } + + # create the overlay and add it to the list of overlays for this hint my $overlay = $self->overlay($col, $row, $self->strwidth($hint), 1, $label_rend, 0); $overlay->set(0, 0, $hint); - $results->{$hint} = {label => $overlay, match => $match}; + push(@{$results->{$hint}->{labels}}, $overlay); } return $results; @@ -188,13 +201,16 @@ sub update { foreach (keys %{$results}) { my $result = $results->{$_}; - my $overlay = $result->{label}; if ($len == 0 || index($_, $p->{buffer}) == 0) { - $overlay->show; + for my $overlay (@{$result->{labels}}) { + $overlay->show; + } unshift @matches, $result->{match}; } else { - $overlay->hide; + for my $overlay (@{$result->{labels}}) { + $overlay->hide; + } } } # Auto-launch a single url only if the launchsingle resource is true |