From c5da709e41a5f7fe6ded2e4d4974e356b3e6633d Mon Sep 17 00:00:00 2001 From: Sterling Camden Date: Wed, 24 Nov 2010 15:58:01 -0800 Subject: Correct search and labeling of URLs in visible scrollback region. --- README | 4 ++-- url-picker | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README b/README index fc12ca3..03a02d8 100644 --- a/README +++ b/README @@ -37,7 +37,7 @@ search for URLs will be restricted to that region. Otherwise, the visible text of the termainl will be used. If no URLs are found, url-picker just pops up an overlay window that -warns "no URLs found on visible screen" or "no URLs found in selected +warns "no URLs found on visible screen" or "no URLs found in visible selected text". The overlay disappears after five seconds, but the terminal is immediately operable. @@ -46,7 +46,7 @@ The browser is determined by X resources url-picker.launcher if defined, otherwise URxvt.urlLauncher. If neither of these are defined, the 'sensible-browser' is used. The URL will be passed as the first argument. -If more than one URL available in the region, url-picker places numbered +If more than one URL is available in the region, url-picker places numbered labels over the first characters of each URL on the screen. A prompt "Follow: " appears at the bottom of the terminal window, at which you can type only numbers, backspace, enter, or escape (all other input is diff --git a/url-picker b/url-picker index adb1831..027d966 100644 --- a/url-picker +++ b/url-picker @@ -14,6 +14,11 @@ my $url = )+ }x; +sub on_view_change { + my ($self, $offset) = @_; + $self->{view_offset} = $offset; +} + sub on_user_command { my ($self, $cmd) = @_; if ($cmd =~ s/^url-picker\b//) { @@ -38,25 +43,26 @@ sub on_user_command { }; my ($brow, $bcol) = $self->selection_beg(); my ($erow, $ecol) = $self->selection_end(); + my $offset = $self->{view_offset} || 0; my $issel = ($ecol > $bcol) || ($erow > $brow); if ($issel) { # restrict to selection if one exists - ($row, $base_col) = ($brow, $bcol); + ($row, $base_col) = ($brow - $offset, $bcol); for (split(/\n/, $self->selection())) { $text = $_; - $label_urls->(); + $label_urls->() if $row >= 0; # must be visible $base_col = 0; $row++; } } else { # no selection, use visible terminal - for (0..$self->nrow) { + for (0..($self->nrow - 1)) { $row = $_; - $text = $self->ROW_t($row); + $text = $self->ROW_t($row + $offset); $label_urls->(); } } if ($num < 1) { - my $desc = $issel ? "in selected text" : "on visible screen"; + my $desc = $issel ? "in visible selected text" : "on visible screen"; $self->status_msg("url-picker: no URLs found $desc"); } else { my $url_picker = {}; -- cgit v1.2.3