core: only adjust selection on keypress

This commit is contained in:
Mitchell Hashimoto
2024-03-13 11:10:25 -07:00
parent a697e97e08
commit 1527936f90
2 changed files with 6 additions and 3 deletions

View File

@ -25,3 +25,4 @@ paged-terminal branch:
- tests and logic for overflowing page capacities: - tests and logic for overflowing page capacities:
* graphemes * graphemes
- there is some bug around adjusting selection up out of viewport

View File

@ -1360,6 +1360,11 @@ pub fn keyCallback(
defer self.renderer_state.mutex.unlock(); defer self.renderer_state.mutex.unlock();
var screen = self.io.terminal.screen; var screen = self.io.terminal.screen;
const sel = if (screen.selection) |*sel| sel else break :adjust_selection; const sel = if (screen.selection) |*sel| sel else break :adjust_selection;
// Silently consume key releases. We only want to process selection
// adjust on press.
if (event.action != .press and event.action != .repeat) return .consumed;
sel.adjust(&screen, switch (event.key) { sel.adjust(&screen, switch (event.key) {
.left => .left, .left => .left,
.right => .right, .right => .right,
@ -1372,9 +1377,6 @@ pub fn keyCallback(
else => break :adjust_selection, else => break :adjust_selection,
}); });
// Silently consume key releases.
if (event.action != .press and event.action != .repeat) return .consumed;
// If the selection endpoint is outside of the current viewpoint, // If the selection endpoint is outside of the current viewpoint,
// scroll it in to view. // scroll it in to view.
// TODO(paged-terminal) // TODO(paged-terminal)