… | |
… | |
7 | and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
7 | and $self->selection (map { y/A-Za-z/N-ZA-Mn-za-m/; $_ } $self->selection); |
8 | |
8 | |
9 | () |
9 | () |
10 | } |
10 | } |
11 | |
11 | |
12 | my @patterns = ( |
12 | my @mark_patterns = ( |
13 | # urls, just a heuristic |
13 | # urls, just a heuristic |
14 | qr{( |
14 | qr{( |
15 | (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
15 | (?:https?|ftp|news|mailto|file)://[ab-zA-Z0-9\-\@;\/?:&=%\$_.+!*\x27(),~]+ |
16 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often |
16 | [ab-zA-Z0-9\-\@;\/?:&=%\$_+!*\x27(),~] # do not include a trailing dot, its wrong too often |
17 | )}x, |
17 | )}x, |
… | |
… | |
28 | | ' [^']* ' |
28 | | ' [^']* ' |
29 | )+ |
29 | )+ |
30 | )}x, |
30 | )}x, |
31 | ); |
31 | ); |
32 | |
32 | |
33 | my $x = "‘hallole’"; |
33 | my @simplify_patterns = ( |
|
|
34 | qr{^"([^\\"'\ \t|&;<>()*?]+)"$}, # "simple" => simple |
|
|
35 | qr{^(.*)[,\-]$}, |
|
|
36 | ); |
34 | |
37 | |
35 | sub on_sel_extend { |
38 | sub on_sel_extend { |
36 | my ($self) = @_; |
39 | my ($self) = @_; |
37 | |
40 | |
38 | my ($row, $col) = $self->selection_mark; |
41 | my ($row, $col) = $self->selection_mark; |
39 | my $line = $self->line ($row); |
42 | my $line = $self->line ($row); |
40 | my $offset = $line->offset_of ($row, $col); |
43 | my $offset = $line->offset_of ($row, $col); |
41 | my $text = $line->t; |
44 | my $text = $line->t; |
42 | |
45 | |
43 | for my $regex (@patterns) { |
46 | for my $regex (@mark_patterns) { |
44 | while ($text =~ /$regex/g) { |
47 | while ($text =~ /$regex/g) { |
45 | if ($-[1] <= $offset and $offset <= $+[1]) { |
48 | if ($-[1] <= $offset and $offset <= $+[1]) { |
|
|
49 | my $match = $1; |
|
|
50 | my ($ofs1, $ofs2) = ($-[1], $+[1]); |
|
|
51 | |
|
|
52 | for my $regex (@simplify_patterns) { |
|
|
53 | if ($match =~ $regex) { |
|
|
54 | $match = $1; |
|
|
55 | $ofs1 += $-[1]; |
|
|
56 | $ofs2 = $ofs1 + length $match; |
|
|
57 | } |
|
|
58 | } |
|
|
59 | |
46 | $self->selection_beg ($line->coord_of ($-[1])); |
60 | $self->selection_beg ($line->coord_of ($ofs1)); |
47 | $self->selection_end ($line->coord_of ($+[1])); |
61 | $self->selection_end ($line->coord_of ($ofs2)); |
48 | return 1; |
62 | return 1; |
49 | } |
63 | } |
50 | } |
64 | } |
51 | } |
65 | } |
52 | |
66 | |