From d60e7d374ca6dc3fe9232514930126edfcdc8ebd Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <bensberg@justemail.net> Date: Thu, 16 Feb 2017 11:44:04 +0100 Subject: [PATCH] spelling: correctly adjust the length of a single-line region When the marked region covers only a single line (or a part of it), its new endpoint is not simply the length of the last line of the spell-checked text, but instead the old endpoint plus the /change/ in length. This fixes https://savannah.gnu.org/bugs/?50316. Reported-by: David Lawrence Ramsey <pooka109@gmail.com> --- src/text.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/text.c b/src/text.c index ad6c4f6c..ab8434aa 100644 --- a/src/text.c +++ b/src/text.c @@ -2926,7 +2926,7 @@ const char *do_alt_speller(char *tempfile_name) bool added_magicline = FALSE; /* Whether we added a magicline after filebot. */ filestruct *top, *bot; - size_t top_x, bot_x; + size_t top_x, bot_x, was_x, new_x; bool right_side_up = FALSE; ssize_t mb_lineno_save = 0; /* We're going to close the current file, and open the output of @@ -3037,9 +3037,17 @@ const char *do_alt_speller(char *tempfile_name) /* Adjust the end point of the marked region for any change in * length of the region's last line. */ if (right_side_up) - current_x_save = strlen(openfile->filebot->data); + was_x = current_x_save; + else + was_x = openfile->mark_begin_x; + if (top == bot) + new_x = was_x - bot_x + top_x + strlen(openfile->filebot->data); + else + new_x = strlen(openfile->filebot->data); + if (right_side_up) + current_x_save = new_x; else - openfile->mark_begin_x = strlen(openfile->filebot->data); + openfile->mark_begin_x = new_x; /* Unpartition the filestruct so that it contains all the text * again. Note that we've replaced the marked text originally -- GitLab