Skip to content

Commit 4821dd4

Browse files
committed
Try different strategy
1 parent 9ec7b43 commit 4821dd4

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

crates/editor/src/editor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23964,6 +23964,10 @@ impl EntityInputHandler for Editor {
2396423964
let utf16_offset = anchor.to_offset_utf16(&position_map.snapshot.buffer_snapshot());
2396523965
Some(utf16_offset.0)
2396623966
}
23967+
23968+
fn input_enabled(&self, _window: &mut Window, _cx: &mut Context<Self>) -> bool {
23969+
self.input_enabled
23970+
}
2396723971
}
2396823972

2396923973
trait SelectionExt {

crates/editor/src/element.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9622,13 +9622,11 @@ impl Element for EditorElement {
96229622
.update(cx, |editor, cx| editor.key_context(window, cx));
96239623

96249624
window.set_key_context(key_context);
9625-
if self.editor.read(cx).input_enabled {
9626-
window.handle_input(
9627-
&focus_handle,
9628-
ElementInputHandler::new(bounds, self.editor.clone()),
9629-
cx,
9630-
);
9631-
}
9625+
window.handle_input(
9626+
&focus_handle,
9627+
ElementInputHandler::new(bounds, self.editor.clone()),
9628+
cx,
9629+
);
96329630
self.register_actions(window, cx);
96339631
self.register_key_listeners(window, cx, layout);
96349632
}

crates/gpui/src/input.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ pub trait EntityInputHandler: 'static + Sized {
7070
window: &mut Window,
7171
cx: &mut Context<Self>,
7272
) -> Option<usize>;
73+
74+
/// See [`InputHandler::input_enabled`] for details
75+
fn input_enabled(&self, _window: &mut Window, _cx: &mut Context<Self>) -> bool {
76+
true
77+
}
7378
}
7479

7580
/// The canonical implementation of [`crate::PlatformInputHandler`]. Call [`Window::handle_input`]
@@ -177,4 +182,9 @@ impl<V: EntityInputHandler> InputHandler for ElementInputHandler<V> {
177182
view.character_index_for_point(point, window, cx)
178183
})
179184
}
185+
186+
fn input_enabled(&mut self, window: &mut Window, cx: &mut App) -> bool {
187+
self.view
188+
.update(cx, |view, cx| view.input_enabled(window, cx))
189+
}
180190
}

crates/gpui/src/platform.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,13 @@ impl PlatformInputHandler {
974974
.ok()
975975
.flatten()
976976
}
977+
978+
pub fn input_enabled(&mut self) -> bool {
979+
self.cx
980+
.update(|window, cx| self.handler.input_enabled(window, cx))
981+
.ok()
982+
.unwrap_or(true)
983+
}
977984
}
978985

979986
/// A struct representing a selection in a text buffer, in UTF16 characters.
@@ -1082,6 +1089,11 @@ pub trait InputHandler: 'static {
10821089
fn apple_press_and_hold_enabled(&mut self) -> bool {
10831090
true
10841091
}
1092+
1093+
/// Returns whether input is currently enabled for this handler.
1094+
fn input_enabled(&mut self, _window: &mut Window, _cx: &mut App) -> bool {
1095+
true
1096+
}
10851097
}
10861098

10871099
/// The variables that can be configured when creating a new window

crates/gpui/src/platform/windows/events.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,12 @@ impl WindowsWindowInner {
11341134
}
11351135

11361136
fn has_input_handler(&self) -> Option<isize> {
1137-
let has_handler = self.state.borrow().input_handler.is_some();
1138-
Some(if has_handler { 1 } else { 0 })
1137+
let mut state = self.state.borrow_mut();
1138+
let has_enabled_handler = state
1139+
.input_handler
1140+
.as_mut()
1141+
.map_or(false, |handler| handler.input_enabled());
1142+
Some(if has_enabled_handler { 1 } else { 0 })
11391143
}
11401144

11411145
#[inline]

0 commit comments

Comments
 (0)