[PATCH] input: prevent most toggles from breaking a series of cuts or copies

Benno Schulenberg <[email protected]> Sun, 15 Feb 2026 16:51:07 +0100
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
Only the cut-from-cursor toggle should break a chain of cuts or copies,
because it affects how those operations behave.  All other toggles have
no effect on those operations nor on the position of the cursor, so they
should not break a chain of cuts or copies.

Achieve this by reshuffling a fragment of code to before the fragment
that triggers cutbuffer clearing for most operations.

(This has as interesting side effect that none of the toggles breaks a
chain of completions either.)

This fixes https://savannah.gnu.org/bugs/?68050.

Bug existed since version 4.3, commit 6c4f228f.
---
 src/nano.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index 8a9d7e3c..cbfdeafa 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1674,6 +1674,15 @@ void process_a_keystroke(void)
 	} else if (meta_key)
 		give_a_hint = FALSE;
 
+#ifndef NANO_TINY
+	if (function == do_toggle) {
+		toggle_this(shortcut->toggle);
+		if (shortcut->toggle == CUT_FROM_CURSOR)
+			keep_cutbuffer = FALSE;
+		return;
+	}
+#endif
+
 	/* When not cutting or copying text, drop the cutbuffer the next time. */
 	if (function != cut_text && function != copy_text) {
 #ifndef NANO_TINY
@@ -1693,13 +1702,6 @@ void process_a_keystroke(void)
 	}
 #endif
 #ifndef NANO_TINY
-	if (function == do_toggle) {
-		toggle_this(shortcut->toggle);
-		if (shortcut->toggle == CUT_FROM_CURSOR)
-			keep_cutbuffer = FALSE;
-		return;
-	}
-
 	linestruct *was_current = openfile->current;
 	size_t was_x = openfile->current_x;
 
-- 
2.53.0