From 75d751e4e3af4df404b17887336b3bfe6568b451 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Mon, 4 Oct 2021 11:31:22 +0200
Subject: [PATCH 30/34] browser: make the keystrokes ^W^Y and ^W^V work again

The functions to_first_file() and to_last_file() can get called from
do_statusbar_input(), which is called indirectly from do_prompt(),
and are expected to make the corresponding adjustment.

This fixes https://savannah.gnu.org/bugs/?61273.

Bug existed since version 5.0, commit 07c1ac90.
---
 src/browser.c    | 15 ++++++++++++++-
 src/global.c     |  6 ------
 src/prototypes.h |  4 ++--
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/browser.c b/src/browser.c
index ed469b84..73c10fe3 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -359,7 +359,8 @@ void search_filename(bool forwards)
 #endif
 	}
 
-	findfile(last_search, forwards);
+	if (response == 0 || response == -2)
+		findfile(last_search, forwards);
 }
 
 /* Search again without prompting for the last given search string,
@@ -380,6 +381,18 @@ void research_filename(bool forwards)
 	}
 }
 
+/* Select the first file in the list -- called by ^W^Y. */
+void to_first_file(void)
+{
+	selected = 0;
+}
+
+/* Select the last file in the list -- called by ^W^V. */
+void to_last_file(void)
+{
+	selected = list_length - 1;
+}
+
 /* Strip one element from the end of path, and return the stripped path.
  * The returned string is dynamically allocated, and should be freed. */
 char *strip_last_component(const char *path)
diff --git a/src/global.c b/src/global.c
index 550c855c..62ce54dc 100644
--- a/src/global.c
+++ b/src/global.c
@@ -298,12 +298,6 @@ void flip_goto(void)
 void to_files(void)
 {
 }
-void to_first_file(void)
-{
-}
-void to_last_file(void)
-{
-}
 void goto_dir(void)
 {
 }
diff --git a/src/prototypes.h b/src/prototypes.h
index f9ac3a9c..efc6a110 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -190,6 +190,8 @@ typedef void (*functionptrtype)(void);
 #ifdef ENABLE_BROWSER
 void browser_refresh(void);
 char *browse_in(const char *inpath);
+void to_first_file(void);
+void to_last_file(void);
 #endif
 
 /* Most functions in chars.c. */
@@ -642,8 +644,6 @@ void flip_replace(void);
 void flip_goto(void);
 #ifdef ENABLE_BROWSER
 void to_files(void);
-void to_first_file(void);
-void to_last_file(void);
 void goto_dir(void);
 #endif
 #ifndef NANO_TINY
-- 
2.29.3

