diff --git a/src/files.c b/src/files.c index 219620b9..487ecbcc 100644 --- a/src/files.c +++ b/src/files.c @@ -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; diff --git a/src/nano.c b/src/nano.c index ae1d5302..bdae4e0e 100644 --- a/src/nano.c +++ b/src/nano.c @@ -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); diff --git a/src/nano.h b/src/nano.h index b33b7d26..6a456fd0 100644 --- a/src/nano.h +++ b/src/nano.h @@ -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. */ diff --git a/src/proto.h b/src/proto.h index 72b33393..b2385064 100644 --- a/src/proto.h +++ b/src/proto.h @@ -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) diff --git a/src/text.c b/src/text.c index ee985e48..32ff0db6 100644 --- a/src/text.c +++ b/src/text.c @@ -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();