From 5310a355ef28fe82796c46cc3972126124433734 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 9 Mar 2020 11:43:50 +0100 Subject: [PATCH] tweaks: reshuffle the trimming of leading whitespace, for compactness --- src/text.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/text.c b/src/text.c index d337d807..da777ac7 100644 --- a/src/text.c +++ b/src/text.c @@ -1858,10 +1858,18 @@ void do_justify(bool full_justify) update_undo(CUT); if (openfile->mark) { - size_t line_len = strlen(cutbuffer->data), indent_len; + size_t line_len = strlen(cutbuffer->data); + size_t white_len = indent_length(cutbuffer->data); size_t needed_bot_extra = (end_x < lead_len ? lead_len - end_x : 0); 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; + } + /* 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 * first line of the extracted region. */ @@ -1869,17 +1877,8 @@ void do_justify(bool full_justify) cutbuffer->data = charealloc(cutbuffer->data, line_len + lead_len + 1); memmove(cutbuffer->data + lead_len, cutbuffer->data, line_len + 1); strncpy(cutbuffer->data, the_lead, lead_len); - line_len += lead_len; } - indent_len = indent_length(cutbuffer->data + lead_len); - - /* Remove extra whitespace after the leading part. */ - if (indent_len > 0) - memmove(cutbuffer->data + lead_len, - cutbuffer->data + lead_len + indent_len, - line_len - lead_len - indent_len + 1); - /* If the marked region ends in the middle of a line, and this line * has a leading part, check if the last line of the extracted region * contains a missing portion of this leading part. If it has no