wrapping: improve the persistence of the prepending behavior

Now you can have a look elsewhere in the buffer (and even delete
or paste stuff there) and when you return to the original line
and continue typing, any spillover from automatic hard-wrapping
will spill over onto the same line it spilled over to before.

You can even switch to a different buffer and return and continue
typing, and stuff will still spill over to the same line.

In the bargain, this gets rid of a bit of flag-resetting code
that was run for many keystrokes, in most cases needlessly.

This addresses https://savannah.gnu.org/bugs/?56189.
master
Benno Schulenberg 2019-04-21 17:31:29 +02:00
parent 1326af7eae
commit 34d22d3f00
5 changed files with 17 additions and 29 deletions

View File

@ -94,6 +94,9 @@ void make_new_buffer(void)
openfile->current_y = 0;
openfile->modified = FALSE;
#ifdef ENABLE_WRAPPING
openfile->spillage_line = NULL;
#endif
#ifndef NANO_TINY
openfile->mark = NULL;

View File

@ -131,6 +131,11 @@ void unlink_node(linestruct *fileptr)
/* Free the data structures in the given node. */
void delete_node(linestruct *fileptr)
{
#ifdef ENABLE_WRAPPING
/* If the spill-over line for hard-wrapping is deleted... */
if (fileptr == openfile->spillage_line)
openfile->spillage_line = NULL;
#endif
free(fileptr->data);
#ifdef ENABLE_COLOR
free(fileptr->multidata);
@ -1780,9 +1785,6 @@ void do_input(void)
} else
#endif
{
#ifdef ENABLE_WRAPPING
linestruct *was_next = openfile->current->next;
#endif
#ifndef NANO_TINY
linestruct *was_current = openfile->current;
size_t was_x = openfile->current_x;
@ -1812,14 +1814,6 @@ void do_input(void)
also_the_last = FALSE;
}
#endif
#ifdef ENABLE_WRAPPING
/* If the cursor moved to another line and this was not caused
* by adding characters to the buffer, clear the prepend flag. */
if (openfile->current->next != was_next &&
shortcut->func != do_tab &&
shortcut->func != do_verbatim_input)
wrap_reset();
#endif
#ifdef ENABLE_COLOR
if (!refresh_needed && !okay_for_view(shortcut))
check_the_multis(openfile->current);

View File

@ -383,6 +383,10 @@ typedef struct openfilestruct {
/* Whether the file has been modified. */
struct stat *current_stat;
/* The file's current stat information. */
#ifdef ENABLE_WRAPPING
linestruct *spillage_line;
/* The line for prepending stuff to during automatic hard-wrapping. */
#endif
#ifndef NANO_TINY
linestruct *mark;
/* The line in the file where the mark is set; NULL if not set. */

View File

@ -525,7 +525,6 @@ void update_multiline_undo(ssize_t lineno, char *indentation);
void update_undo(undo_type action);
#endif /* !NANO_TINY */
#ifdef ENABLE_WRAPPING
void wrap_reset(void);
bool do_wrap(void);
#endif
#if defined(ENABLE_HELP) || defined(ENABLED_WRAPORJUSTIFY)

View File

@ -35,11 +35,6 @@
static pid_t pid_of_command = -1;
/* The PID of the forked process -- needed when wanting to abort it. */
#endif
#ifdef ENABLE_WRAPPING
static bool prepend_wrap = FALSE;
/* Should we prepend wrapped text to the next line? */
#endif
#ifdef ENABLE_WORDCOMPLETION
static int pletion_x = 0;
/* The x position in pletion_line of the last found completion. */
@ -1412,13 +1407,6 @@ void update_undo(undo_type action)
#endif /* !NANO_TINY */
#ifdef ENABLE_WRAPPING
/* Unset the prepend_wrap flag. We need to do this as soon as we do
* something other than type text. */
void wrap_reset(void)
{
prepend_wrap = FALSE;
}
/* When the current line is overlong, hard-wrap it at the furthest possible
* whitespace character, and (if possible) prepend the remainder of the line
* to the next line. Return TRUE if wrapping occurred, and FALSE otherwise. */
@ -1466,7 +1454,8 @@ bool do_wrap(void)
/* When prepending and the remainder of this line will not make the next
* line too long, then join the two lines, so that, after the line wrap,
* the remainder will effectively have been prefixed to the next line. */
if (prepend_wrap && rest_length + strlenpt(line->next->data) <= wrap_at) {
if (openfile->spillage_line && openfile->spillage_line == line->next &&
rest_length + strlenpt(line->next->data) <= wrap_at) {
/* Go to the end of this line. */
openfile->current_x = line_len;
@ -1511,14 +1500,13 @@ bool do_wrap(void)
/* Now split the line. */
do_enter();
openfile->spillage_line = openfile->current;
if (cursor_x < wrap_loc) {
openfile->current = openfile->current->prev;
openfile->current_x = cursor_x;
prepend_wrap = TRUE;
} else {
} else
openfile->current_x += (cursor_x - wrap_loc);
prepend_wrap = FALSE;
}
openfile->placewewant = xplustabs();