From 6851c22f74ec3bad19abe98374c09c14cf66c40e Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Mon, 24 Mar 2003 18:52:02 +0000 Subject: [PATCH] * view.c (get_line_at): Set prev properly for reverse search. Don't remove final character in the last line without newline. (search): During regexp search: handle properly '^' in forward search and '$' in reverse search. Based on the patch from Adam Byrtek . --- src/ChangeLog | 8 ++++++++ src/view.c | 34 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 2dc4ae552..8a7dd978e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-03-24 Andrew V. Samoilov + + * view.c (get_line_at): Set prev properly for reverse search. + Don't remove final character in the last line without newline. + (search): During regexp search: handle properly '^' + in forward search and '$' in reverse search. + Based on the patch from Adam Byrtek . + 2003-03-22 Andrew V. Samoilov * cons.handler.c (set_attr) [__FreeBSD__]: Fix compilation. diff --git a/src/view.c b/src/view.c index ee0ed1a79..9c48a6dac 100644 --- a/src/view.c +++ b/src/view.c @@ -1545,29 +1545,30 @@ get_line_at (WView *view, unsigned long *p, unsigned long *skipped) } *skipped = i; - if (pos) { - prev = get_byte (view, pos - 1); + if (!i && (pos || direction == -1)) { + prev = get_byte (view, pos - direction); if ((prev == -1) || (prev == '\n')) prev = 0; } - for (i = 0; ch != -1; ch = get_byte (view, pos)) { + for (i = 1; ch != -1; ch = get_byte (view, pos)) { - if (i == usable_size) { + if (i >= usable_size) { buffer = grow_string_buffer (buffer, &buffer_size); - usable_size = buffer_size - 2; + usable_size = buffer_size - 2; /* prev & null terminator */ } - i++; - buffer[i] = ch; + buffer[i++] = ch; if (!pos && direction == -1) break; pos += direction; - if (ch == '\n' || !ch) + if (ch == '\n' || !ch) { + i--; /* Strip newline/zero */ break; + } } if (buffer) { @@ -1675,20 +1676,19 @@ search (WView *view, char *text, /* We found the string */ - if (*s && !view->search_start && (search == regexp_view_search) - && (*text == '^')) { - - /* We do not want to match a - * ^ regexp when not at the real - * beginning of some line - */ - continue; + /* Handle ^ and $ when regexp search starts at the middle of the line */ + if (*s && !view->search_start && (search == regexp_view_search)) { + if ((*text == '^' && view->direction == 1) + || (view->direction == -1 && text[strlen (text) - 1] == '$') + ) { + continue; + } } /* Record the position used to continue the search */ if (view->direction == 1) t += forward_line_start; else - t = reverse_line_start ? reverse_line_start + 2 : 0; + t = reverse_line_start ? reverse_line_start + 3 : 0; view->search_start += t; if (t != beginning) {