[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] input: read in an external paste in one go, to allow undoing wit
From: |
Benno Schulenberg |
Subject: |
[PATCH] input: read in an external paste in one go, to allow undoing with one M-U |
Date: |
Thu, 16 Jan 2020 13:22:08 +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 da99e353..1ba312a0 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1463,6 +1463,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)
@@ -1622,6 +1656,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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] input: read in an external paste in one go, to allow undoing with one M-U,
Benno Schulenberg <=