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

Comparing rxvt-unicode/src/perl/searchable-scrollback (file contents):
Revision 1.36 by sf-exg, Sat May 31 08:33:47 2014 UTC vs.
Revision 1.41 by sf-exg, Tue Oct 14 09:00:52 2014 UTC

44 or warn "unable to register '$hotkey' as scrollback search start hotkey\n"; 44 or warn "unable to register '$hotkey' as scrollback search start hotkey\n";
45 45
46 () 46 ()
47} 47}
48 48
49sub on_user_command {
50 my ($self, $cmd) = @_;
51
52 $cmd eq "searchable-scrollback:start"
53 and $self->enter;
54
55 ()
56}
57
49sub on_action { 58sub on_action {
50 my ($self, $action) = @_; 59 my ($self, $action) = @_;
51 60
52 $action eq "start" 61 $action eq "start"
53 and $self->enter; 62 and $self->enter;
92 $self->pty_ev_events ($self->{pty_ev_events}); 101 $self->pty_ev_events ($self->{pty_ev_events});
93 102
94 delete $self->{manpage_overlay}; 103 delete $self->{manpage_overlay};
95 delete $self->{overlay}; 104 delete $self->{overlay};
96 delete $self->{search}; 105 delete $self->{search};
106 delete $self->{found};
97} 107}
98 108
99sub idle { 109sub idle {
100 my ($self) = @_; 110 my ($self) = @_;
101 111
102 $self->msg ("(escape cancels) /$self->{search}█"); 112 $self->msg ("(escape cancels) /$self->{search}█");
103} 113}
104 114
105sub search { 115sub search {
106 my ($self, $dir) = @_; 116 my ($self, $dir, $row) = @_;
107
108 delete $self->{found};
109 my $row = $self->{row};
110 117
111 my $search = $self->special_encode ($self->{search}); 118 my $search = $self->special_encode ($self->{search});
112 119
113 no re 'eval'; # just to be sure 120 no re 'eval'; # just to be sure
114 if (my $re = eval { qr/$search/ }) { 121 if (my $re = eval { qr/$search/ }) {
116 my $line = $self->line ($row) 123 my $line = $self->line ($row)
117 or last; 124 or last;
118 125
119 my $text = $line->t; 126 my $text = $line->t;
120 if ($text =~ /$re/g) { 127 if ($text =~ /$re/g) {
128 delete $self->{found};
129
121 do { 130 do {
122 push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])]; 131 push @{ $self->{found} }, [$line->coord_of ($-[0]), $line->coord_of ($+[0])];
123 } while $text =~ /$re/g; 132 } while $text =~ /$re/g;
124 133
125 $self->{row} = $row; 134 $self->{row} = $row;
126 $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1)); 135 $self->view_start (List::Util::min 0, $row - ($self->nrow >> 1));
127 $self->want_refresh; 136 $self->want_refresh;
128 last; 137 return;
129 } 138 }
130 139
131 $row = $dir < 0 ? $line->beg - 1 : $line->end + 1; 140 $row = $dir < 0 ? $line->beg - 1 : $line->end + 1;
132 } 141 }
133 } 142 }
134 143
135 $self->scr_bell unless $self->{found}; 144 $self->scr_bell;
136} 145}
137 146
138sub refresh { 147sub refresh {
139 my ($self) = @_; 148 my ($self) = @_;
140 149
167 $self->leave; 176 $self->leave;
168 } elsif ($keysym == 0xff57) { # end 177 } elsif ($keysym == 0xff57) { # end
169 $self->{row} = $self->nrow - 1; 178 $self->{row} = $self->nrow - 1;
170 $self->view_start (0); 179 $self->view_start (0);
171 } elsif ($keysym == 0xff52) { # up 180 } elsif ($keysym == 0xff52) { # up
172 $self->{row}-- if $self->{row} > $self->top_row; 181 my $line = $self->line ($self->{row});
173 $self->search (-1); 182 $self->search (-1, $line->beg - 1)
183 if $line->beg > $self->top_row;
174 } elsif ($keysym == 0xff54) { # down 184 } elsif ($keysym == 0xff54) { # down
175 $self->{row}++ if $self->{row} < $self->nrow; 185 my $line = $self->line ($self->{row});
176 $self->search (+1); 186 $self->search (+1, $line->end + 1)
187 if $line->end < $self->nrow;
177 } elsif ($keysym == 0xff08) { # backspace 188 } elsif ($keysym == 0xff08) { # backspace
178 substr $self->{search}, -1, 1, ""; 189 substr $self->{search}, -1, 1, "";
179 $self->search; 190 $self->search (+1, $self->{row});
180 $self->idle; 191 $self->idle;
181 } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) { 192 } elsif ($string !~ /[\x00-\x1f\x80-\xaf]/) {
182 return; # pass to tt_write 193 return; # pass to tt_write
183 } 194 }
184 195
191 $self->{search} .= $self->locale_decode ($data); 202 $self->{search} .= $self->locale_decode ($data);
192 203
193 $self->{search} =~ s/^\(\?i\)// 204 $self->{search} =~ s/^\(\?i\)//
194 if $self->{search} =~ /^\(.*[[:upper:]]/; 205 if $self->{search} =~ /^\(.*[[:upper:]]/;
195 206
207 delete $self->{found};
196 $self->search (-1); 208 $self->search (-1, $self->{row});
197 $self->idle; 209 $self->idle;
198 210
199 1 211 1
200} 212}
201 213

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines