tweaks: handle two similar things in the same way

master
Benno Schulenberg 2020-07-26 11:49:42 +02:00
parent 6ca22b80ef
commit bccb0ea0bb
2 changed files with 7 additions and 11 deletions

View File

@ -472,7 +472,7 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
void do_replace(void); void do_replace(void);
void ask_for_and_do_replacements(void); void ask_for_and_do_replacements(void);
void goto_line_posx(ssize_t line, size_t pos_x); void goto_line_posx(ssize_t line, size_t pos_x);
void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer, void do_gotolinecolumn(ssize_t line, ssize_t column, bool retain_answer,
bool interactive); bool interactive);
void do_gotolinecolumn_void(void); void do_gotolinecolumn_void(void);
#ifndef NANO_TINY #ifndef NANO_TINY

View File

@ -69,14 +69,10 @@ void tidy_up_after_search(void)
/* Prepare the prompt and ask the user what to search for. Keep looping /* Prepare the prompt and ask the user what to search for. Keep looping
* as long as the user presses a toggle, and only take action and exit * as long as the user presses a toggle, and only take action and exit
* when <Enter> is pressed or a non-toggle shortcut was executed. */ * when <Enter> is pressed or a non-toggle shortcut was executed. */
void search_init(bool replacing, bool keep_the_answer) void search_init(bool replacing, bool retain_answer)
{ {
char *thedefault; char *thedefault;
/* What will be searched for when the user typed nothing. */ /* What will be searched for when the user types just <Enter>. */
/* When starting a new search, clear the current answer. */
if (!keep_the_answer)
answer = mallocstrcpy(answer, "");
/* If something was searched for earlier, include it in the prompt. */ /* If something was searched for earlier, include it in the prompt. */
if (*last_search != '\0') { if (*last_search != '\0') {
@ -95,7 +91,7 @@ void search_init(bool replacing, bool keep_the_answer)
/* Ask the user what to search for (or replace). */ /* Ask the user what to search for (or replace). */
int response = do_prompt( int response = do_prompt(
inhelp ? MFINDINHELP : (replacing ? MREPLACE : MWHEREIS), inhelp ? MFINDINHELP : (replacing ? MREPLACE : MWHEREIS),
answer, &search_history, edit_refresh, retain_answer ? answer : "", &search_history, edit_refresh,
/* TRANSLATORS: This is the main search prompt. */ /* TRANSLATORS: This is the main search prompt. */
"%s%s%s%s%s%s", _("Search"), "%s%s%s%s%s%s", _("Search"),
/* TRANSLATORS: The next four modify the search prompt. */ /* TRANSLATORS: The next four modify the search prompt. */
@ -751,12 +747,12 @@ void goto_line_posx(ssize_t line, size_t pos_x)
/* Go to the specified line and column, or ask for them if interactive /* Go to the specified line and column, or ask for them if interactive
* is TRUE. In the latter case also update the screen afterwards. * is TRUE. In the latter case also update the screen afterwards.
* Note that both the line and column number should be one-based. */ * Note that both the line and column number should be one-based. */
void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer, void do_gotolinecolumn(ssize_t line, ssize_t column, bool retain_answer,
bool interactive) bool interactive)
{ {
if (interactive) { if (interactive) {
/* Ask for the line and column. */ /* Ask for the line and column. */
int response = do_prompt(MGOTOLINE, use_answer ? answer : "", NULL, int response = do_prompt(MGOTOLINE, retain_answer ? answer : "", NULL,
/* TRANSLATORS: This is a prompt. */ /* TRANSLATORS: This is a prompt. */
edit_refresh, _("Enter line number, column number")); edit_refresh, _("Enter line number, column number"));
@ -768,7 +764,7 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
if (func_from_key(&response) == flip_goto) { if (func_from_key(&response) == flip_goto) {
UNSET(BACKWARDS_SEARCH); UNSET(BACKWARDS_SEARCH);
/* Retain what the user typed so far and switch to searching. */ /* Switch to searching but retain what the user typed so far. */
search_init(FALSE, TRUE); search_init(FALSE, TRUE);
return; return;
} }