From 8b378e9a44111891f7a58ddb8f7be78136962a80 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 24 Jul 2022 09:15:47 +0200 Subject: [PATCH] Make complete-or-search select the first candidate Our pager computes the selected completion based on its rendering. The number of rows affect the selection, in particular when moving left from the top left cell. This computation breaks if the number of rows is zero, which happens in at least two scenarios: 1. If the completion pager was not shown (as is the case for complete-or-search) 2. If the search field had filtered away every candidate but not anymore. I believe in these scenarios the selected completion index is always 0, so let's fix the selection for that case. Probably too minor for a changelog entry. Closes #9080 --- src/pager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pager.cpp b/src/pager.cpp index 110ddc5ce..df703b627 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -778,11 +778,17 @@ bool pager_t::select_next_completion_in_direction(selection_motion_t direction, size_t pager_t::visual_selected_completion_index(size_t rows, size_t cols) const { // No completions -> no selection. - if (completion_infos.empty() || rows == 0 || cols == 0) { + if (completion_infos.empty()) { return PAGER_SELECTION_NONE; } size_t result = selected_completion_idx; + if (result == 0) { + return result; + } + if (rows == 0 || cols == 0) { + return PAGER_SELECTION_NONE; + } if (result != PAGER_SELECTION_NONE) { // If the selected completion is beyond the last selection, go left by columns until it's // within it. This is how we implement "column memory".