commit c457f744ef5a821cd2363ec55f10313600f9fcff
parent 8f3ea23ece9750bd03531fa9e9c80327bab94a43
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 9 Mar 2020 14:00:30 +0100
justify: trim the leading blanks of a marked region at the right moment
This fixes https://savannah.gnu.org/bugs/?57977.
Bug existed since commit 5310a355 from three hours ago.
Diffstat:
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/text.c b/src/text.c
@@ -1862,15 +1862,9 @@ void do_justify(bool full_justify)
if (openfile->mark) {
size_t line_len = strlen(cutbuffer->data);
- size_t white_len = indent_length(cutbuffer->data);
linestruct *line;
-
- /* Trim any whitespace at the start of the extracted region. */
- if (white_len > 0) {
- memmove(cutbuffer->data, cutbuffer->data + white_len,
- line_len - white_len + 1);
- line_len -= white_len;
- }
+ size_t white_len;
+ char *afterlead;
/* If the marked region started in the middle of a line, and this line
* has a leading part, then prepend this same leading part also to the
@@ -1881,6 +1875,13 @@ void do_justify(bool full_justify)
strncpy(cutbuffer->data, the_lead, lead_len);
}
+ afterlead = cutbuffer->data + lead_len;
+ white_len = indent_length(afterlead);
+
+ /* If the marked region started with whitespace, trim it. */
+ if (white_len > 0)
+ memmove(afterlead, afterlead + white_len, line_len - white_len + 1);
+
/* Now justify the extracted region. */
concat_paragraph(&cutbuffer, linecount);
squeeze(cutbuffer, lead_len);