[Pager] Wrap cardinal direction movement

Fixes #4669.
This commit is contained in:
Fabian Homborg 2018-01-23 10:39:02 +01:00
parent 462b9c2209
commit 13079911bc

View File

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