commit 877a649819d1e3412b21bba8e48a80e498645795
parent 5d7b723c1670b04a4e7a1204ae95f831b8a7eea5
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 8 Jan 2019 16:42:04 -0600
justify: when justifying a marked region, strip whitespace after the lead
This matches Pico's behavior.
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/text.c b/src/text.c
@@ -2151,6 +2151,7 @@ void do_justify(bool full_justify)
update_undo(CUT);
if (openfile->mark) {
+ size_t line_len = strlen(cutbuffer->data), indent_len;
size_t needed_top_extra = (top_x < lead_len ? top_x : lead_len);
size_t needed_bot_extra = (bot_x < lead_len ? lead_len - bot_x : 0);
filestruct *line;
@@ -2159,13 +2160,12 @@ void do_justify(bool full_justify)
* has a leading part, prepend any missing portion of this leading part
* to the first line of the extracted region. */
if (needed_top_extra > 0) {
- size_t line_len = strlen(cutbuffer->data);
-
cutbuffer->data = charealloc(cutbuffer->data,
line_len + needed_top_extra + 1);
charmove(cutbuffer->data + needed_top_extra, cutbuffer->data,
line_len + 1);
strncpy(cutbuffer->data, the_lead, needed_top_extra);
+ line_len += needed_top_extra;
/* If it has no missing portion, we don't need to prepend anything
* below. */
@@ -2173,6 +2173,14 @@ void do_justify(bool full_justify)
needed_top_extra = 0;
}
+ indent_len = indent_length(cutbuffer->data + lead_len);
+
+ /* Remove extra whitespace after the leading part. */
+ if (indent_len > 0)
+ charmove(cutbuffer->data + lead_len,
+ cutbuffer->data + lead_len + indent_len,
+ line_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