>From 8908b222ec724cc98406df4d5631d2f73e7afefd Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Thu, 20 Jul 2017 19:59:40 +0530 Subject: [PATCH] new feature: allow pasting at all input prompts Include the shortcut for Uncut into most menus, and add an Uncut function for the status bar, so that it becomes possible to paste the first line of the cutbuffer at any text-input prompt. This fulfills https://savannah.gnu.org/bugs/?48501. Requested-by: Benno Schulenberg Signed-off-by: Rishabh Dave --- src/global.c | 4 ++-- src/prompt.c | 22 +++++++++++++++++++++- src/proto.h | 1 + src/rcfile.c | 4 ++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/global.c b/src/global.c index 03e8561d..1574b6b9 100644 --- a/src/global.c +++ b/src/global.c @@ -1063,8 +1063,8 @@ void shortcut_init(void) add_to_sclist(MMAIN, "F14", 0, do_replace, 0); add_to_sclist(MMOST, "^K", 0, do_cut_text_void, 0); add_to_sclist(MMOST, "F9", 0, do_cut_text_void, 0); - add_to_sclist(MMAIN, "^U", 0, do_uncut_text, 0); - add_to_sclist(MMAIN, "F10", 0, do_uncut_text, 0); + add_to_sclist(MMOST, "^U", 0, do_uncut_text, 0); + add_to_sclist(MMOST, "F10", 0, do_uncut_text, 0); #ifndef DISABLE_JUSTIFY add_to_sclist(MMAIN, "^J", 0, do_justify_void, 0); add_to_sclist(MMAIN, "F4", 0, do_justify_void, 0); diff --git a/src/prompt.c b/src/prompt.c index 5c6b03db..2568b3b1 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -145,7 +145,10 @@ int do_statusbar_input(bool *ran_func, bool *finished) do_statusbar_delete(); else if (s->scfunc == do_backspace) do_statusbar_backspace(); - else { + else if (s->scfunc == do_uncut_text) { + if (cutbuffer != NULL) + do_statusbar_uncut_text(); + } else { /* Handle any other shortcut in the current menu, setting * ran_func to TRUE if we try to run their associated functions, * and setting finished to TRUE to indicatethat we're done after @@ -363,6 +366,23 @@ size_t statusbar_xplustabs(void) return strnlenpt(answer, statusbar_x); } +/* Paste the first line of the cutbuffer into the current answer. */ +void do_statusbar_uncut_text(void) +{ + int pastelen = strlen(cutbuffer->data); + char *fusion = malloc((strlen(answer) + pastelen + 1) * sizeof(char)); + + /* Concatenate: the current answer before the cursor, the first line + * of the cutbuffer, plus the rest of the current answer. */ + strncpy(fusion, answer, statusbar_x); + strncpy(fusion + statusbar_x, cutbuffer->data, pastelen); + strcpy(fusion + statusbar_x + pastelen, answer + statusbar_x); + + free(answer); + answer = fusion; + statusbar_x += pastelen; +} + /* Return the column number of the first character of the answer that is * displayed in the statusbar when the cursor is at the given column, * with the available room for the answer starting at base. Note that diff --git a/src/proto.h b/src/proto.h index 34d4343c..f44c3095 100644 --- a/src/proto.h +++ b/src/proto.h @@ -448,6 +448,7 @@ void do_statusbar_right(void); void do_statusbar_backspace(void); void do_statusbar_delete(void); void do_statusbar_cut_text(void); +void do_statusbar_uncut_text(void); #ifndef NANO_TINY void do_statusbar_prev_word(void); void do_statusbar_next_word(void); diff --git a/src/rcfile.c b/src/rcfile.c index 95fe88a5..069c3e27 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -357,9 +357,9 @@ bool is_universal(void (*func)(void)) #ifndef NANO_TINY func == do_prev_word_void || func == do_next_word_void || #endif - func == do_verbatim_input || func == do_cut_text_void || func == do_delete || func == do_backspace || - func == do_tab || func == do_enter) + func == do_cut_text_void || func == do_uncut_text || + func == do_tab || func == do_enter || func == do_verbatim_input) return TRUE; else return FALSE; -- 2.13.2