Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23964,6 +23964,10 @@ impl EntityInputHandler for Editor {
let utf16_offset = anchor.to_offset_utf16(&position_map.snapshot.buffer_snapshot());
Some(utf16_offset.0)
}

fn accepts_text_input(&self, _window: &mut Window, _cx: &mut Context<Self>) -> bool {
self.input_enabled
}
}

trait SelectionExt {
Expand Down
10 changes: 10 additions & 0 deletions crates/gpui/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ pub trait EntityInputHandler: 'static + Sized {
window: &mut Window,
cx: &mut Context<Self>,
) -> Option<usize>;

/// See [`InputHandler::accepts_text_input`] for details
fn accepts_text_input(&self, _window: &mut Window, _cx: &mut Context<Self>) -> bool {
true
}
}

/// The canonical implementation of [`crate::PlatformInputHandler`]. Call [`Window::handle_input`]
Expand Down Expand Up @@ -177,4 +182,9 @@ impl<V: EntityInputHandler> InputHandler for ElementInputHandler<V> {
view.character_index_for_point(point, window, cx)
})
}

fn accepts_text_input(&mut self, window: &mut Window, cx: &mut App) -> bool {
self.view
.update(cx, |view, cx| view.accepts_text_input(window, cx))
}
}
6 changes: 6 additions & 0 deletions crates/gpui/src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub struct KeyDownEvent {

/// Whether the key is currently held down.
pub is_held: bool,

/// Whether the modifiers are excessive for producing this character.
/// When false, the modifiers are essential for character input (e.g., AltGr),
/// and character input should be prioritized over keybindings.
/// When true, the modifiers are for keybindings (e.g., Ctrl+A).
pub are_modifiers_excessive: bool,
}

impl Sealed for KeyDownEvent {}
Expand Down
10 changes: 10 additions & 0 deletions crates/gpui/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,11 @@ impl PlatformInputHandler {
.ok()
.flatten()
}

#[allow(dead_code)]
pub(crate) fn accepts_text_input(&mut self, window: &mut Window, cx: &mut App) -> bool {
self.handler.accepts_text_input(window, cx)
}
}

/// A struct representing a selection in a text buffer, in UTF16 characters.
Expand Down Expand Up @@ -1082,6 +1087,11 @@ pub trait InputHandler: 'static {
fn apple_press_and_hold_enabled(&mut self) -> bool {
true
}

/// Returns whether this handler is accepting text input to be inserted.
fn accepts_text_input(&mut self, _window: &mut Window, _cx: &mut App) -> bool {
true
}
}

/// The variables that can be configured when creating a new window
Expand Down
3 changes: 3 additions & 0 deletions crates/gpui/src/platform/linux/wayland/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
let input = PlatformInput::KeyDown(KeyDownEvent {
keystroke: keystroke.clone(),
is_held: false,
are_modifiers_excessive: true,
});

state.repeat.current_id += 1;
Expand All @@ -1363,6 +1364,7 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
let input = PlatformInput::KeyDown(KeyDownEvent {
keystroke,
is_held: true,
are_modifiers_excessive: true,
});
move |_event, _metadata, this| {
let mut client = this.get_client();
Expand Down Expand Up @@ -1447,6 +1449,7 @@ impl Dispatch<zwp_text_input_v3::ZwpTextInputV3, ()> for WaylandClientStatePtr {
key_char: Some(commit_text),
},
is_held: false,
are_modifiers_excessive: true,
}));
} else {
window.handle_ime(ImeInput::InsertText(commit_text));
Expand Down
1 change: 1 addition & 0 deletions crates/gpui/src/platform/linux/x11/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ impl X11Client {
window.handle_input(PlatformInput::KeyDown(crate::KeyDownEvent {
keystroke,
is_held: false,
are_modifiers_excessive: true,
}));
}
Event::KeyRelease(event) => {
Expand Down
1 change: 1 addition & 0 deletions crates/gpui/src/platform/mac/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl PlatformInput {
NSEventType::NSKeyDown => Some(Self::KeyDown(KeyDownEvent {
keystroke: parse_keystroke(native_event),
is_held: native_event.isARepeat() == YES,
are_modifiers_excessive: false,
})),
NSEventType::NSKeyUp => Some(Self::KeyUp(KeyUpEvent {
keystroke: parse_keystroke(native_event),
Expand Down
1 change: 1 addition & 0 deletions crates/gpui/src/platform/mac/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,7 @@ extern "C" fn do_command_by_selector(this: &Object, _: Sel, _: Sel) {
let handled = (callback)(PlatformInput::KeyDown(KeyDownEvent {
keystroke,
is_held: false,
are_modifiers_excessive: false,
}));
state.as_ref().lock().do_command_handled = Some(!handled.propagate);
}
Expand Down
Loading
Loading