Simplify input handling (#3282)

This PR takes a different approach to input handling.

Rather than returning the optional input handler, focus handle pair from
the element trait, we instead allow you to register an input handler
imperatively on the window context with `WindowContext::handle_input`.
You pass a focus handle reference and any implementer of
`PlatformInputHandler`. There's an `ElementInputHandler<V>` that
implements `PlatformWindowHandler` so long as `V` implements
`InputHandler`.

Release Notes:

- N/A
This commit is contained in:
Nathan Sobo 2023-11-08 22:27:36 -07:00 committed by GitHub
commit 8c44f6a814
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 145 additions and 218 deletions

View file

@ -9580,7 +9580,7 @@ impl Render for Editor {
impl InputHandler for Editor {
fn text_for_range(
&self,
&mut self,
range_utf16: Range<usize>,
cx: &mut ViewContext<Self>,
) -> Option<String> {
@ -9593,7 +9593,7 @@ impl InputHandler for Editor {
)
}
fn selected_text_range(&self, cx: &mut ViewContext<Self>) -> Option<Range<usize>> {
fn selected_text_range(&mut self, cx: &mut ViewContext<Self>) -> Option<Range<usize>> {
// Prevent the IME menu from appearing when holding down an alphabetic key
// while input is disabled.
if !self.input_enabled {