mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-22 12:51:23 +03:00
text: copy leading quote characters when automatic hard-wrapping occurs
When the user is typing a long text and --breaklonglines is in effect, then any leading comment or quoting characters are automatically added to each automatic new line. This fulfills https://savannah.gnu.org/bugs/?56042. Requested-by: Sébastien Desreux <seb@h-k.fr>
This commit is contained in:
parent
4314b8ded3
commit
8fce33afe0
@ -533,6 +533,7 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl);
|
||||
size_t indent_length(const char *line);
|
||||
#endif
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
size_t quote_length(const char *line);
|
||||
bool begpar(const linestruct *const foo, int depth);
|
||||
bool inpar(const linestruct *const foo);
|
||||
void do_justify(bool full_justify);
|
||||
|
43
src/text.c
43
src/text.c
@ -1426,6 +1426,13 @@ bool do_wrap(void)
|
||||
|
||||
add_undo(SPLIT_BEGIN);
|
||||
#endif
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
bool autowhite = ISSET(AUTOINDENT);
|
||||
size_t lead_len = quote_length(line->data);
|
||||
|
||||
if (lead_len > 0)
|
||||
UNSET(AUTOINDENT);
|
||||
#endif
|
||||
|
||||
/* The remainder is the text that will be wrapped to the next line. */
|
||||
remainder = line->data + wrap_loc;
|
||||
@ -1455,10 +1462,19 @@ bool do_wrap(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Join the next line to this one, and delete any extra blanks. */
|
||||
do {
|
||||
/* Join the next line to this one. */
|
||||
do_delete();
|
||||
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
/* If the quoting part of the current line equals the quoting part of
|
||||
* what was the next line, then strip this second quoting part. */
|
||||
if (strncmp(line->data, line->data + openfile->current_x, lead_len) == 0)
|
||||
for (size_t i = lead_len; i > 0; i--)
|
||||
do_delete();
|
||||
#endif
|
||||
/* Remove any extra blanks. */
|
||||
while (is_blank_mbchar(&line->data[openfile->current_x]))
|
||||
do_delete();
|
||||
} while (is_blank_mbchar(&line->data[openfile->current_x]));
|
||||
}
|
||||
|
||||
/* Go to the wrap location. */
|
||||
@ -1480,6 +1496,27 @@ bool do_wrap(void)
|
||||
/* Now split the line. */
|
||||
do_enter();
|
||||
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
/* If the original line has quoting, copy it to the spillage line. */
|
||||
if (lead_len > 0) {
|
||||
lead_len += indent_length(line->data + lead_len);
|
||||
|
||||
line = line->next;
|
||||
line_len = strlen(line->data);
|
||||
line->data = charealloc(line->data, lead_len + line_len + 1);
|
||||
|
||||
charmove(line->data + lead_len, line->data, line_len + 1);
|
||||
strncpy(line->data, line->prev->data, lead_len);
|
||||
|
||||
openfile->current_x += lead_len;
|
||||
#ifndef NANO_TINY
|
||||
update_undo(ENTER);
|
||||
#endif
|
||||
if (autowhite)
|
||||
SET(AUTOINDENT);
|
||||
}
|
||||
#endif
|
||||
|
||||
openfile->spillage_line = openfile->current;
|
||||
|
||||
if (cursor_x < wrap_loc) {
|
||||
|
Loading…
Reference in New Issue
Block a user