nano-devel
[Top][All Lists]
Advanced

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

[PATCH 1/2] input: read in an external paste in one go, to allow undoing


From: Benno Schulenberg
Subject: [PATCH 1/2] input: read in an external paste in one go, to allow undoing with one M-U
Date: Fri, 17 Jan 2020 17:02:31 +0100

This makes an external paste (with mouse or <Shift+Insert>) behave
the same as an internal paste (^U), and also inherently suppresses
auto-indentation, automatic hard-wrapping, and tab conversion.

This fulfills https://savannah.gnu.org/bugs/?54950.
---
 src/nano.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/nano.c b/src/nano.c
index 201dc8e0..cf87d71d 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1467,6 +1467,40 @@ bool okay_for_view(const keystruct *shortcut)
        return (item == NULL || item->viewok);
 }
 
+/* Read in all waiting input bytes and paste them into the buffer in one go. */
+void suck_up_input_and_paste_it(void)
+{
+       linestruct *was_cutbuffer = cutbuffer;
+       linestruct *line = make_new_node(NULL);
+       size_t index = 0;
+
+       cutbuffer = line;
+       line->data = copy_of("");
+
+       while (bracketed_paste) {
+               int input = get_kbinput(edit, BLIND);
+
+               if (input == CR_CODE) {
+                       line->next = make_new_node(line);
+                       line = line->next;
+                       line->data = copy_of("");
+                       index = 0;
+               } else if ((input > 0x1F && input <= 0xFF && input != DEL_CODE) 
||
+                                                                               
                        input == TAB_CODE) {
+                       line->data = charealloc(line->data, index + 2);
+                       line->data[index++] = (char)input;
+                       line->data[index] = '\0';
+               } else if (input != BRACKETED_PASTE_MARKER)
+                       beep();
+       }
+
+       cutbottom = line;
+
+       paste_text();
+
+       cutbuffer = was_cutbuffer;
+}
+
 /* Read in a keystroke.  Act on the keystroke if it is a shortcut or a toggle;
  * otherwise, insert it into the edit buffer. */
 void do_input(void)
@@ -1626,6 +1660,9 @@ void do_input(void)
        if (!refresh_needed && (shortcut->func == do_delete ||
                                                        shortcut->func == 
do_backspace))
                update_line(openfile->current, openfile->current_x);
+
+       if (bracketed_paste)
+               suck_up_input_and_paste_it();
 }
 
 /* The user typed output_len multibyte characters.  Add them to the edit
-- 
2.24.1




reply via email to

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