ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/perl/selection
(Generate patch)

Comparing rxvt-unicode/src/perl/selection (file contents):
Revision 1.31 by root, Thu Jan 19 09:47:15 2006 UTC vs.
Revision 1.32 by root, Sat Jan 21 21:20:34 2006 UTC

67 my $curlen = $line->offset_of ($self->selection_end) 67 my $curlen = $line->offset_of ($self->selection_end)
68 - $line->offset_of ($self->selection_beg); 68 - $line->offset_of ($self->selection_beg);
69 69
70 my @matches; 70 my @matches;
71 71
72 # not doing matches in unicode mode helps speed 72 if ($markofs < $line->l) {
73 # enourmously here. working in utf-8 should be 73 # convert markofs form character to UTF-8 offset space
74 # equivalent due to the magic of utf-8 encoding. 74 {
75 my $prefix = substr $text, 0, $markofs;
75 utf8::encode $text; 76 utf8::encode $prefix;
76 study $text; # _really_ helps, too :) 77 $markofs = length $prefix;
78 }
77 79
78 for my $regex (@mark_patterns, @{ $self->{patterns} }) { 80 # not doing matches in unicode mode helps speed
79 while ($text =~ /$regex/g) { 81 # enourmously here. working in utf-8 should be
80 if ($-[1] <= $markofs and $markofs <= $+[1]) { 82 # equivalent due to the magic of utf-8 encoding.
81 my $ofs = $-[1]; 83 utf8::encode $text;
82 my $match = $1; 84 study $text; # _really_ helps, too :)
83 85
86 for my $regex (@mark_patterns, @{ $self->{patterns} }) {
87 while ($text =~ /$regex/g) {
88 if ($-[1] <= $markofs and $markofs <= $+[1]) {
89 my $ofs = $-[1];
90 my $match = $1;
91
84 for my $regex (@simplify_patterns) { 92 for my $regex (@simplify_patterns) {
85 if ($match =~ $regex) { 93 if ($match =~ $regex) {
86 $match = $1; 94 $match = $1;
87 $ofs += $-[1]; 95 $ofs += $-[1];
96 }
88 } 97 }
98
99 push @matches, [$ofs, length $match];
89 } 100 }
90
91 push @matches, [$ofs, length $match];
92 } 101 }
93 } 102 }
94 } 103 }
95 104
96 # whole line 105 # whole line
99 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) { 108 for (sort { $a->[1] <=> $b->[1] or $b->[0] <=> $a->[0] } @matches) {
100 my ($ofs, $len) = @$_; 109 my ($ofs, $len) = @$_;
101 110
102 next if $len <= $curlen; 111 next if $len <= $curlen;
103 112
113 # convert back from UTF-8 offset space to character space
114 {
115 my $length = substr $text, $ofs, $len;
116 utf8::decode $length;
117 $len = length $length;
118 }
119 {
120 my $prefix = substr $text, 0, $ofs;
121 utf8::decode $prefix;
122 $ofs = length $prefix;
123 }
124
104 $self->selection_beg ($line->coord_of ($ofs)); 125 $self->selection_beg ($line->coord_of ($ofs));
105 $self->selection_end ($line->coord_of ($ofs + $len)); 126 $self->selection_end ($line->coord_of ($ofs + $len));
106 return 1; 127 return 1;
107 } 128 }
108 129

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines