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 <bensberg@telfort.nl>
Signed-off-by: Rishabh Dave <rishabhddave@gmail.com>
master
Rishabh Dave 2017-07-20 19:59:40 +05:30 committed by Benno Schulenberg
parent 5dcf375f33
commit 829a1a5050
4 changed files with 26 additions and 5 deletions

View File

@ -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);

View File

@ -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)
{
size_t pastelen = strlen(cutbuffer->data);
char *fusion = charalloc(strlen(answer) + pastelen + 1);
/* 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

View File

@ -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);

View File

@ -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;