From 87b7b6b2bb8e79ffd8d02ffb0427dd2f37f57a28 Mon Sep 17 00:00:00 2001
From: ridiculousfish <corydoras@ridiculousfish.com>
Date: Tue, 22 Jan 2019 14:33:47 -0800
Subject: [PATCH] Make control-S begin navigating the pager contents

In addition to showing the search field, actually allow the user to type in
it.
---
 CHANGELOG.md   | 1 +
 src/reader.cpp | 7 ++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 47413cdec..31fab2284 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@
 - exec now behaves properly inside functions (#5449)
 - while loops now evaluate to the last executed command in the loop body (or zero if the body was empty), matching POSIX semantics.
 - fish does not hang on launch when running under Cygwin/MSYS2
+- The pager-toggle-search binding (by default Control-S) now positions the cursor in the completions list.
 
 
 # fish 3.0.0 (released December 28, 2018)
diff --git a/src/reader.cpp b/src/reader.cpp
index b2c241952..34b0df044 100644
--- a/src/reader.cpp
+++ b/src/reader.cpp
@@ -2728,10 +2728,15 @@ const wchar_t *reader_readline(int nchars) {
                 break;
             }
             case R_PAGER_TOGGLE_SEARCH: {
-                if (data->is_navigating_pager_contents()) {
+                if (!data->pager.empty()) {
+                    // Toggle search, and begin navigating if we are now searching.
                     bool sfs = data->pager.is_search_field_shown();
                     data->pager.set_search_field_shown(!sfs);
                     data->pager.set_fully_disclosed(true);
+                    if (data->pager.is_search_field_shown() &&
+                        !data->is_navigating_pager_contents()) {
+                        select_completion_in_direction(direction_south);
+                    }
                     reader_repaint_needed();
                 }
                 break;