From 6a49efb858649bfe1f8a1ffa41df7208a3f0969b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 28 Nov 2021 11:47:49 +0100 Subject: Shift the hints so they don't obscure the match. --- reselect | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/reselect b/reselect index 81161fe..98524c8 100644 --- a/reselect +++ b/reselect @@ -78,6 +78,18 @@ sub find_matches { return { matches => \@matches, unique_count => scalar(keys %{$unique_matches})}; } +sub place_hint { + my ($match_col, $match_row, $hint_w) = @_; + + # place the thint so it does not obscure the match, if possible + $match_col -= $hint_w; + if ($match_col < 0) { + $match_col = 0; + } + + return ($match_col, $match_row); +} + sub build_overlays { my ($self, $pattern, $text, $rowmap) = @_; @@ -99,15 +111,17 @@ sub build_overlays { if (not exists $match_hints->{$match}) { $match_hints->{$match} = $hints->(); } - my $hint = $match_hints->{$match}; + my $hint = $match_hints->{$match}; + my $hint_w = $self->strwidth($hint); + + ($col, $row) = place_hint($col, $row, $hint_w); 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); + my $overlay = $self->overlay($col, $row, $hint_w, 1, $label_rend, 0); $overlay->set(0, 0, $hint); push(@{$results->{$hint}->{labels}}, $overlay); -- cgit v1.2.3