nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] cutting: when deleting whole words, don't join line


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] cutting: when deleting whole words, don't join lines unexpectedly
Date: Sun, 2 Sep 2018 13:30:40 +0200

[This isn't the desired behavior that I described (which, it turns out,
is almost exactly how Firefox and Thunderbird behave for Ctrl+Bsp and
Ctrl+Del), but I quite like it.  And it costs less than fifteen lines.]
---
 src/text.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/text.c b/src/text.c
index b3e9d4dd..484e1726 100644
--- a/src/text.c
+++ b/src/text.c
@@ -205,11 +205,24 @@ void do_cutword(bool backward)
        cutbuffer = NULL;
        cutbottom = NULL;
 
-       /* Move the cursor to a word start, to the left or to the right. */
-       if (backward)
+       /* Move the cursor to a word start, to the left or to the right.
+        * If that word is on another line and the cursor was not already
+        * on the edge of the original line, then put the cursor there
+        * instead, so that lines will not be joined unexpectedly. */
+       if (backward) {
                do_prev_word(ISSET(WORD_BOUNDS), FALSE);
-       else
+               if (openfile->current != is_current && is_current_x > 0) {
+                       openfile->current = is_current;
+                       openfile->current_x = 0;
+               }
+       } else {
                do_next_word(FALSE, ISSET(WORD_BOUNDS), FALSE);
+               if (openfile->current != is_current &&
+                                               is_current->data[is_current_x] 
!= '\0') {
+                       openfile->current = is_current;
+                       openfile->current_x = strlen(is_current->data);
+               }
+       }
 
        /* Set the mark at the start of that word. */
        openfile->mark = openfile->current;
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]