[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH V3] wrapping: improve the persistence of the prepend
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH V3] wrapping: improve the persistence of the prepending behavior |
Date: |
Mon, 22 Apr 2019 18:44:19 +0200 |
V3: Prevent the tiny possibility that memory from a deleted spill-over line
getting reused for a new linestruct could cause unexpected prepending.
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.
---
src/files.c | 3 +++
src/nano.c | 15 ++++-----------
src/nano.h | 4 ++++
src/proto.h | 1 -
src/text.c | 22 +++++-----------------
5 files changed, 16 insertions(+), 29 deletions(-)
diff --git a/src/files.c b/src/files.c
index f9a4fd6b..f6698c0c 100644
--- a/src/files.c
+++ b/src/files.c
@@ -95,6 +95,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 e775a763..fa11e772 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -131,6 +131,10 @@ void unlink_node(linestruct *fileptr)
/* Free the data structures in the given node. */
void delete_node(linestruct *fileptr)
{
+ /* If the spill-over line for hard-wrapping is deleted... */
+ if (fileptr == openfile->spillage_line)
+ openfile->spillage_line = NULL;
+
free(fileptr->data);
#ifdef ENABLE_COLOR
free(fileptr->multidata);
@@ -1781,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;
@@ -1813,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 5fb1ca74..2609416b 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -523,7 +523,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 7442cee7..3c0d5ab2 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();
--
2.20.1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nano-devel] [PATCH V3] wrapping: improve the persistence of the prepending behavior,
Benno Schulenberg <=