diff --git a/src/pager.cpp b/src/pager.cpp index 0f0151e90..175d343df 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -669,7 +669,11 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio current_row--; } else { current_row = rendering.rows - 1; - if (current_col > 0) current_col--; + if (current_col > 0) { + current_col--; + } else { + current_col = rendering.cols - 1; + } } break; } @@ -685,14 +689,14 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio break; } case direction_south: { - // Go down, unless we are in the last row. Note that this means that we may set - // selected_completion_idx to an out-of-bounds value if the last row is incomplete; - // this is a feature (it allows "last column memory"). - if (current_row + 1 < rendering.rows) { + // Go down, unless we are in the last row. + // If we go over the last element, wrap to the first. + if (current_row + 1 < rendering.rows && + current_col * rendering.rows + current_row + 1 < completion_infos.size()) { current_row++; } else { current_row = 0; - if (current_col + 1 < rendering.cols) current_col++; + current_col = (current_col + 1) % rendering.cols; } break; } @@ -704,7 +708,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio current_col++; } else { current_col = 0; - if (current_row + 1 < rendering.rows) current_row++; + current_row = (current_row + 1) % rendering.rows; } break; } @@ -714,7 +718,11 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio current_col--; } else { current_col = rendering.cols - 1; - if (current_row > 0) current_row--; + if (current_row > 0) { + current_row--; + } else { + current_row = rendering.rows - 1; + } } break; }