Merge pull request #684 from mitchellh/scroll-input

core: scroll viewport back to bottom on any key input that isn't a mod
This commit is contained in:
Mitchell Hashimoto
2023-10-15 09:09:58 -07:00
committed by GitHub
2 changed files with 22 additions and 4 deletions

View File

@ -1032,12 +1032,13 @@ pub fn keyCallback(
}, .{ .forever = {} }); }, .{ .forever = {} });
try self.io_thread.wakeup.notify(); try self.io_thread.wakeup.notify();
// If we have printable text to emit then we always want to clear the // If our event is any keypress that isn't a modifier and we generated
// selection and scroll to the bottom. // some data to send to the pty, then we move the viewport down to the
if (event.utf8.len > 0) { // bottom. If we generated literal text, then we also clear the selection.
if (!event.key.modifier()) {
self.renderer_state.mutex.lock(); self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock(); defer self.renderer_state.mutex.unlock();
self.setSelection(null); if (event.utf8.len > 0) self.setSelection(null);
try self.io.terminal.scrollViewport(.{ .bottom = {} }); try self.io.terminal.scrollViewport(.{ .bottom = {} });
try self.queueRender(); try self.queueRender();
} }

View File

@ -332,6 +332,23 @@ pub const Key = enum(c_int) {
}; };
} }
/// True if this key is a modifier.
pub fn modifier(self: Key) bool {
return switch (self) {
.left_shift,
.left_control,
.left_alt,
.left_super,
.right_shift,
.right_control,
.right_alt,
.right_super,
=> true,
else => false,
};
}
/// Returns true if this is a keypad key. /// Returns true if this is a keypad key.
pub fn keypad(self: Key) bool { pub fn keypad(self: Key) bool {
return switch (self) { return switch (self) {