mirror of
git://git.sv.gnu.org/nano.git
synced 2025-03-30 13:23:20 +03:00
tweaks: reshuffle the trimming of leading whitespace, for compactness
This commit is contained in:
parent
d7875cdf4f
commit
5310a355ef
19
src/text.c
19
src/text.c
@ -1858,10 +1858,18 @@ void do_justify(bool full_justify)
|
|||||||
update_undo(CUT);
|
update_undo(CUT);
|
||||||
|
|
||||||
if (openfile->mark) {
|
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);
|
size_t needed_bot_extra = (end_x < lead_len ? lead_len - end_x : 0);
|
||||||
linestruct *line;
|
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
|
/* 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
|
* has a leading part, then prepend this same leading part also to the
|
||||||
* first line of the extracted region. */
|
* 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);
|
cutbuffer->data = charealloc(cutbuffer->data, line_len + lead_len + 1);
|
||||||
memmove(cutbuffer->data + lead_len, cutbuffer->data, line_len + 1);
|
memmove(cutbuffer->data + lead_len, cutbuffer->data, line_len + 1);
|
||||||
strncpy(cutbuffer->data, the_lead, lead_len);
|
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
|
/* 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
|
* 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
|
* contains a missing portion of this leading part. If it has no
|
||||||
|
Loading…
x
Reference in New Issue
Block a user