From: Benno Schulenberg Date: Sat, 7 Nov 2015 09:49:34 +0000 (+0000) Subject: Correcting the logic for adjusting the x position of the mark, X-Git-Tag: v2.5.0~67 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=a1c03ed5c1a96740f2395991262b1135b340fa94;p=nano.git Correcting the logic for adjusting the x position of the mark, and improving the comments. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5395 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index ee71843e..1a916ea3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-11-07 Benno Schulenberg + * src/search.c (do_replace_loop): Correct the logic for adjusting the + x position of the mark -- it happened to work because 'mark_begin' is + NULL when 'old_mark_set' is FALSE. Also improve the comments. + 2015-11-06 Benno Schulenberg * src/files.c (write_lockfile): Don't bail out when the hostname is overlong, but instead truncate it properly and continue. This fixes diff --git a/src/search.c b/src/search.c index 843729ff..0562f985 100644 --- a/src/search.c +++ b/src/search.c @@ -747,14 +747,12 @@ ssize_t do_replace_loop( length_change = strlen(copy) - strlen(openfile->current->data); #ifndef NANO_TINY - /* If the mark was on and (mark_begin, mark_begin_x) was the - * top of it, don't change mark_begin_x. */ - if (!old_mark_set || !right_side_up) { - /* Keep mark_begin_x in sync with the text changes. */ + /* If the mark was on and it was located after the cursor, + * then adjust its x position for any text length changes. */ + if (old_mark_set && !right_side_up) { if (openfile->current == openfile->mark_begin && openfile->mark_begin_x > openfile->current_x) { - if (openfile->mark_begin_x < openfile->current_x + - match_len) + if (openfile->mark_begin_x < openfile->current_x + match_len) openfile->mark_begin_x = openfile->current_x; else openfile->mark_begin_x += length_change; @@ -762,11 +760,10 @@ ssize_t do_replace_loop( } } - /* If the mark was on and (current, current_x) was the top - * of it, don't change real_current_x. */ + /* If the mark was not on or it was before the cursor, then + * adjust the cursor's x position for any text length changes. */ if (!old_mark_set || right_side_up) { #endif - /* Keep real_current_x in sync with the text changes. */ if (openfile->current == real_current && openfile->current_x <= *real_current_x) { if (*real_current_x < openfile->current_x + match_len)