Register text input handlers via new element hook

Provide element bounds to the input handler's `bounds_for_rect` method.

Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-11-08 15:48:55 -08:00
parent d273fa6dd0
commit 1a37d9edc6
7 changed files with 160 additions and 66 deletions

View file

@ -17,10 +17,11 @@ use collections::{BTreeMap, HashMap};
use gpui::{
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
Edges, Element, ElementId, Entity, GlobalElementId, Hsla, KeyDownEvent, KeyListener, KeyMatch,
Line, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
ScrollWheelEvent, ShapedGlyph, Size, Style, TextRun, TextStyle, TextSystem, ViewContext,
WindowContext,
Edges, Element, ElementId, Entity, FocusHandle, GlobalElementId, Hsla, InputHandler,
InputHandlerView, KeyDownEvent, KeyListener, KeyMatch, Line, LineLayout, Modifiers,
MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels, ScrollWheelEvent,
ShapedGlyph, Size, Style, TextRun, TextStyle, TextSystem, ViewContext, WindowContext,
WrappedLineLayout,
};
use itertools::Itertools;
use language::language_settings::ShowWhitespaceSetting;
@ -2502,10 +2503,6 @@ impl Element<Editor> for EditorElement {
size: layout.text_size,
};
if editor.focus_handle.is_focused(cx) {
cx.handle_text_input();
}
cx.with_content_mask(ContentMask { bounds }, |cx| {
self.paint_mouse_listeners(
bounds,
@ -2521,6 +2518,14 @@ impl Element<Editor> for EditorElement {
self.paint_text(text_bounds, &layout, editor, cx);
});
}
fn handle_text_input<'a>(
&self,
editor: &'a mut Editor,
cx: &mut ViewContext<Editor>,
) -> Option<(Box<dyn InputHandlerView>, &'a FocusHandle)> {
Some((Box::new(cx.view()), &editor.focus_handle))
}
}
// impl EditorElement {