aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-11-28 11:47:49 +0100
committerAnton Khirnov <anton@khirnov.net>2021-11-28 11:47:49 +0100
commit6a49efb858649bfe1f8a1ffa41df7208a3f0969b (patch)
tree5c16475dde2ae131dfa730e90f85d7f4e9fd4fc4
parent8dec307b5c563e419806e0024e9ca11b8340c5c4 (diff)
Shift the hints so they don't obscure the match.
-rw-r--r--reselect20
1 files 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);