From ee2a8e23ac79de4210422648ee61ff7aaad100c3 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Thu, 20 Jul 2017 19:59:40 +0530 Subject: [PATCH] new feature: enable uncut at all prompts Enable the shortcut for uncut at prompts too. Signed-off-by: Rishabh Dave --- src/global.c | 6 ++++-- src/prompt.c | 25 +++++++++++++++++++++++++ src/proto.h | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/global.c b/src/global.c index 03e8561..2c662fb 100644 --- a/src/global.c +++ b/src/global.c @@ -1063,8 +1063,10 @@ 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 & ~MBROWSER & ~MLINTER & ~MSPELL) | MYESNO, + "^U", 0, do_uncut_text, 0); + add_to_sclist((MMOST & ~MBROWSER & ~MLINTER & ~MSPELL) | MYESNO, + "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 5c6b03d..ad473d9 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -145,6 +145,8 @@ int do_statusbar_input(bool *ran_func, bool *finished) do_statusbar_delete(); else if (s->scfunc == do_backspace) do_statusbar_backspace(); + else if (s->scfunc == do_uncut_text) + 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, @@ -363,6 +365,29 @@ size_t statusbar_xplustabs(void) return strnlenpt(answer, statusbar_x); } +void do_statusbar_uncut_text(void) +{ + char *fusion = NULL; + int pastelen; + + if (cutbuffer == NULL) + return; + + pastelen = strlen(cutbuffer->data); + + fusion = (char *) malloc((strlen(answer) + pastelen + 1) * sizeof(char)); + + /* Concatenate the head of the current answer, the first line of the + * cutbuffer plus the tail 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 34d4343..f44c309 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); -- 2.9.4