From 3b657a26a67a444cbce5cb2480cae00fe76a9fef Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 29 Jan 2022 17:41:38 +0100 Subject: [PATCH] prompt: allow the user to copy the answer to the cutbuffer (with M-6) Since version 2.8.7 the user can paste text at the prompt (with ^U), but the ability to copy what is present at the prompt was overlooked. For feedback, the cursor is moved to the start of the answer -- like it moves to the start of the next line when in the edit buffer. This addresses https://savannah.gnu.org/bugs/?61702. Reported-by: Tasos Papastylianou --- src/global.c | 6 +++--- src/prompt.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/global.c b/src/global.c index a74edba7..ac511acd 100644 --- a/src/global.c +++ b/src/global.c @@ -805,7 +805,7 @@ void shortcut_init(void) add_to_funcs(do_mark, MMAIN, N_("Set Mark"), WITHORSANS(mark_gist), TOGETHER, VIEW); - add_to_funcs(copy_text, MMAIN, + add_to_funcs(copy_text, MMOST, N_("Copy"), WITHORSANS(copy_gist), BLANKAFTER, VIEW); #endif @@ -1240,8 +1240,8 @@ void shortcut_init(void) add_to_sclist(MMAIN, "M-A", 0, do_mark, 0); add_to_sclist(MMAIN, "^6", 0, do_mark, 0); add_to_sclist(MMAIN, "^^", 0, do_mark, 0); - add_to_sclist(MMAIN, "M-6", 0, copy_text, 0); - add_to_sclist(MMAIN, "M-^", 0, copy_text, 0); + add_to_sclist(MMOST, "M-6", 0, copy_text, 0); + add_to_sclist(MMOST, "M-^", 0, copy_text, 0); add_to_sclist(MMAIN, "M-}", 0, do_indent, 0); add_to_sclist(MMAIN, "", INDENT_KEY, do_indent, 0); add_to_sclist(MMAIN, "M-{", 0, do_unindent, 0); diff --git a/src/prompt.c b/src/prompt.c index 94d6c5f1..8763f909 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -166,6 +166,17 @@ void do_statusbar_cut_text(void) answer[typing_x] = '\0'; } +/* Copy the current answer (if any) into the cutbuffer. */ +void copy_the_answer(void) +{ + if (*answer) { + free_lines(cutbuffer); + cutbuffer = make_new_node(NULL); + cutbuffer->data = copy_of(answer); + typing_x = 0; + } +} + /* Paste the first line of the cutbuffer into the current answer. */ void paste_into_answer(void) { @@ -344,6 +355,8 @@ int do_statusbar_input(bool *finished) do_statusbar_delete(); else if (shortcut->func == do_backspace) do_statusbar_backspace(); + else if (shortcut->func == copy_text) + copy_the_answer(); else if (shortcut->func == paste_text) { if (cutbuffer != NULL) paste_into_answer();