[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--;
} 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;
}