From b76f8d0939c1a0a59050e53a38dfbe9cd850eff1 Mon Sep 17 00:00:00 2001 From: Leroy Hopson Date: Mon, 27 Jun 2022 00:41:24 +0700 Subject: [PATCH] Prevent scrollback buffer reset when using copy shortcut Prevents scrollback buffer reset (i.e. scrolling to the bottom of terminal output) when pressing modifier keys in isolation or when copying text using the shortcut Ctrl+Shift+C. --- CHANGELOG.md | 2 ++ addons/godot_xterm/terminal.gd | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be38e3f..5fcad13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Shortcuts starting with Ctrl + Shift. This includes the remaining default terminal panel shortcuts such as 'Copy' (Ctrl+Shift+C) and 'New Terminal' (Ctrl+Shift+T). - Target Godot version from 3.3.2-stable -> 3.4.4-stable. +- Prevent scrollback buffer reset (i.e. scrolling to the bottom of terminal output) when + pressing modifier keys in isolation or when copying text using the shortcut Ctrl+Shift+C. ### Removed - Removed custom TerminalSettings Resource type. diff --git a/addons/godot_xterm/terminal.gd b/addons/godot_xterm/terminal.gd index 49503ae..3868031 100644 --- a/addons/godot_xterm/terminal.gd +++ b/addons/godot_xterm/terminal.gd @@ -175,8 +175,14 @@ func _refresh(): func _gui_input(event): _native_terminal._gui_input(event) - if event is InputEventKey: - _native_terminal.sb_reset() # Return to bottom of scrollback buffer if we scrolled up. + if event is InputEventKey and event.pressed: + # Return to bottom of scrollback buffer if we scrolled up. Ignore modifier + # keys pressed in isolation or if Ctrl+Shift modifier keys are pressed. + if ( + not event.scancode in [KEY_ALT, KEY_SHIFT, KEY_CONTROL, KEY_META, KEY_MASK_CMD] + and not (event.control and event.shift) + ): + _native_terminal.sb_reset() _handle_mouse_wheel(event) _handle_selection(event)