mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-23 21:29:39 +03:00
wrapping: never break in the quoting part nor in the indentation part
Rationale: nano should not wrap inside the quoting part of a line
because it would change the quoting level, which would misrepresent
things, nor should it wrap inside the indentation part because when
the user tries to indent something beyond the target wrapping width,
she/he does not intend to create a line containing only whitespace,
but effectively wants to push the text beyond the wrapping width.
This copies the behavior of the rewrap_paragraph() routine that is
used during justification, so that automatic hard-wrapping ends up
with the same result as justifying.
Also, always do automatic hard-wrapping when --breaklonglines is in
effect, also when --autoindent is active.
This fixes https://savannah.gnu.org/bugs/?57425.
The bug was old -- it existed since at least version 2.0.6.
This furthermore avoids https://savannah.gnu.org/bugs/?57422.
Reported-by: Sébastien Desreux <seb@h-k.fr>
That bug existed since version 4.4, commit 8fce33af
.
This commit is contained in:
parent
b00c1d6110
commit
a0055f3640
15
src/text.c
15
src/text.c
@ -1405,6 +1405,8 @@ bool do_wrap(void)
|
||||
/* The line to be wrapped, if needed and possible. */
|
||||
size_t line_len = strlen(line->data);
|
||||
/* The length of this line. */
|
||||
size_t pre_len = quote_length(line->data);
|
||||
/* The length of the leading quoting, plus later also indentation. */
|
||||
size_t cursor_x = openfile->current_x;
|
||||
/* The current cursor position, for comparison with the wrap point. */
|
||||
ssize_t wrap_loc;
|
||||
@ -1414,25 +1416,24 @@ bool do_wrap(void)
|
||||
size_t rest_length;
|
||||
/* The length of the remainder. */
|
||||
|
||||
pre_len += indent_length(line->data + pre_len);
|
||||
|
||||
/* First find the last blank character where we can break the line. */
|
||||
wrap_loc = break_line(line->data, wrap_at, FALSE);
|
||||
wrap_loc = break_line(line->data + pre_len,
|
||||
wrap_at - wideness(line->data, pre_len), FALSE);
|
||||
|
||||
/* If no wrapping point was found before end-of-line, we don't wrap. */
|
||||
if (wrap_loc == -1 || line->data[wrap_loc] == '\0')
|
||||
if (wrap_loc == -1 || wrap_loc + pre_len == line_len)
|
||||
return FALSE;
|
||||
|
||||
/* Step forward to the character just after the blank. */
|
||||
wrap_loc = step_right(line->data, wrap_loc);
|
||||
wrap_loc = step_right(line->data + pre_len, wrap_loc) + pre_len;
|
||||
|
||||
/* When now at end-of-line, no need to wrap. */
|
||||
if (line->data[wrap_loc] == '\0')
|
||||
return FALSE;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
/* When autoindenting, we don't wrap right after the indentation. */
|
||||
if (ISSET(AUTOINDENT) && wrap_loc == indent_length(line->data))
|
||||
return FALSE;
|
||||
|
||||
add_undo(SPLIT_BEGIN, NULL);
|
||||
#endif
|
||||
#ifdef ENABLE_JUSTIFY
|
||||
|
Loading…
Reference in New Issue
Block a user