aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-06-02 10:21:17 +0200
committerAnton Khirnov <anton@khirnov.net>2021-06-02 10:21:17 +0200
commitfb606d51f9cbae3af58e85f272a6ac155081e489 (patch)
tree8f9122e0138eef72920c432a305291e5365085b0
parente28e6e5287c0219275e0d0ae8132970e352eb12f (diff)
Factor out finding matches.
-rw-r--r--url-picker45
1 files changed, 28 insertions, 17 deletions
diff --git a/url-picker b/url-picker
index 03ee55a..37b2dea 100644
--- a/url-picker
+++ b/url-picker
@@ -12,6 +12,32 @@ my $re_url =
)+
}x;
+sub find_matches {
+ my ($text, $rowmap) = @_;
+
+ my @overlays;
+ while ($text =~ /$re_url/g) {
+ my $ndx = $-[0];
+ my $href = $&;
+ my $col = 0;
+ my $row = 0;
+
+ for my $key (keys %$rowmap) {
+ my $value = $rowmap->{$key};
+ my ($start, $end) = @$value;
+ if (($start <= $ndx) && ($end >= $ndx)) {
+ $row = $key;
+ $col = $ndx - $start;
+ last;
+ }
+ }
+ my @ov = ($col, $row, $href);
+ push(@overlays, \@ov) if ($row >= 0);
+ }
+
+ return @overlays;
+}
+
sub on_user_command {
my ($self, $cmd) = @_;
if ($cmd =~ s/^url-picker\b//) {
@@ -25,23 +51,8 @@ sub on_user_command {
my $label_rend = $self->get_rend("label", urxvt::OVERLAY_RSTYLE);
my $label_urls = sub {
- my @overlays;
- while ($text =~ /$re_url/g) {
- my $ndx = $-[0];
- my $href = $&;
- my $col = 0;
- for my $key (keys %$rowmap) {
- my $value = $rowmap->{$key};
- my ($start, $end) = @$value;
- if (($start <= $ndx) && ($end >= $ndx)) {
- $row = $key;
- $col = $ndx - $start;
- last;
- }
- }
- my @ov = ($col, $row, $href);
- push(@overlays, \@ov) if ($row >= 0);
- }
+ my @overlays = find_matches($text, $rowmap);
+
@overlays = reverse @overlays if ($self->{descending});
for my $ov (@overlays) {
my ($col, $row, $href) = @$ov;