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
This commit is contained in:
Johannes Altmanninger
2022-07-24 09:15:47 +02:00
parent 65a9983954
commit 8b378e9a44

View File

@@ -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".