History

linux: Don't insert characters if modifiers other than shift are held (#33424)

Closes #32219 #29666 Release Notes: - Linux: Now skips insertion of characters when modifiers are held. Before, characters were inserted if there's no match in the keymap.

Michael Sloan committed 1 year ago

Commit dfdeb1b1 parent b9f81c72 files · +18 −13Browse files

Unified · Split

2 files
  1. crates/gpui/src/platform/linux/wayland/window.rs +8 −6
  2. crates/gpui/src/platform/linux/x11/window.rs +10 −7
crates/gpui/src/platform/linux/wayland/window.rs+8−6
@@ -699,12 +699,14 @@ impl WaylandWindowStatePtr { · 698 unmodified lines
699699 }
700700 }
701701 if let PlatformInput::KeyDown(event) = input {
702− if let Some(key_char) = &event.keystroke.key_char {
703− let mut state = self.state.borrow_mut();
704− if let Some(mut input_handler) = state.input_handler.take() {
705− drop(state);
706− input_handler.replace_text_in_range(None, key_char);
707− self.state.borrow_mut().input_handler = Some(input_handler);
702+ if event.keystroke.modifiers.is_subset_of(&Modifiers::shift()) {
703+ if let Some(key_char) = &event.keystroke.key_char {
704+ let mut state = self.state.borrow_mut();
705+ if let Some(mut input_handler) = state.input_handler.take() {
706+ drop(state);
707+ input_handler.replace_text_in_range(None, key_char);
708+ self.state.borrow_mut().input_handler = Some(input_handler);
709+ }
708710 }
709711 }
710712 }
crates/gpui/src/platform/linux/x11/window.rs+10−7
@@ -982,14 +982,17 @@ impl X11WindowStatePtr { · 981 unmodified lines
982982 }
983983 }
984984 if let PlatformInput::KeyDown(event) = input {
985− let mut state = self.state.borrow_mut();
986− if let Some(mut input_handler) = state.input_handler.take() {
987− if let Some(key_char) = &event.keystroke.key_char {
988− drop(state);
989− input_handler.replace_text_in_range(None, key_char);
990− state = self.state.borrow_mut();
985+ // only allow shift modifier when inserting text
986+ if event.keystroke.modifiers.is_subset_of(&Modifiers::shift()) {
987+ let mut state = self.state.borrow_mut();
988+ if let Some(mut input_handler) = state.input_handler.take() {
989+ if let Some(key_char) = &event.keystroke.key_char {
990+ drop(state);
991+ input_handler.replace_text_in_range(None, key_char);
992+ state = self.state.borrow_mut();
993+ }
994+ state.input_handler = Some(input_handler);
991995 }
992− state.input_handler = Some(input_handler);
993996 }
994997 }
995998 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t