From e68375c3d43057b9ab6fd80c34236921b8a068ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Wed, 5 Nov 2014 22:13:23 +0100 Subject: [PATCH] url-select: catch button presses, fixes issue #54 --- url-select | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/url-select b/url-select index 7983800..1f6c679 100644 --- a/url-select +++ b/url-select @@ -167,9 +167,25 @@ sub on_button_press { urxvt::ShiftMask | urxvt::ControlMask; if ($event->{button} == $self->{button} && ($event->{state} & $mask) == $self->{state}) { - $self->{button_pressed} = 1; - $self->{button_col} = $event->{col}; - $self->{button_row} = $event->{row}; + my $col = $event->{col}; + my $row = $event->{row}; + my $line = $self->line($row); + my $text = $line->t; + + for my $pattern (@{$self->{pattern}}) { + while ($text =~ /$pattern/g) { + my ($url, $beg, $end) = ($&, $-[0], $+[0]); + --$end if $url =~ s/["')]$//; + + if ($col >= $beg && $col <= $end) { + $self->{button_pressed} = 1; + $self->{button_col} = $col; + $self->{button_row} = $row; + $self->{button_url} = $url; + return 1; + } + } + } } () @@ -185,20 +201,8 @@ sub on_button_release { $self->{button_pressed} = 0; if ($col == $self->{button_col} && $row == $self->{button_row}) { - my $line = $self->line($row); - my $text = $line->t; - - for my $pattern (@{$self->{pattern}}) { - while ($text =~ /$pattern/g) { - my ($url, $beg, $end) = ($&, $-[0], $+[0]); - --$end if $url =~ s/["')]$//; - - if ($col >= $beg && $col <= $end) { - $self->exec_async(@{$self->{browser}}, $url); - return 1; - } - } - } + $self->exec_async(@{$self->{browser}}, $self->{button_url}); + return 1; } }