Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add docs
Nathan Sobod52c5646b451
diff --git a/crates/gpui2/src/input.rs b/crates/gpui2/src/input.rsindex 8d9e9b01ad6..d768ce946a1 100644--- a/crates/gpui2/src/input.rs+++ b/crates/gpui2/src/input.rs@@ -1,6 +1,10 @@use crate::{AsyncWindowContext, Bounds, Pixels, PlatformInputHandler, View, ViewContext};use std::ops::Range;+/// Implement this trait to allow views to handle textual input when implementing an editor, field, etc.+///+/// Once your view `V` implements this trait, you can use it to construct an [ElementInputHandler<V>].+/// This input handler can then be assigned during paint by calling [WindowContext::handle_input].pub trait InputHandler: 'static + Sized {fn text_for_range(&mut self, range: Range<usize>, cx: &mut ViewContext<Self>)-> Option<String>;@@ -28,6 +32,8 @@ pub trait InputHandler: 'static + Sized {) -> Option<Bounds<Pixels>>;}+/// The canonical implementation of `PlatformInputHandler`. Call `WindowContext::handle_input`+/// with an instance during your element's paint.pub struct ElementInputHandler<V> {view: View<V>,element_bounds: Bounds<Pixels>,@@ -35,6 +41,8 @@ pub struct ElementInputHandler<V> {}impl<V: 'static> ElementInputHandler<V> {+ /// Used in [Element::paint] with the element's bounds and a view context for its+ /// containing view.pub fn new(element_bounds: Bounds<Pixels>, cx: &mut ViewContext<V>) -> Self {ElementInputHandler {view: cx.view(),diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rsindex b72793b9986..29980a486b7 100644--- a/crates/gpui2/src/window.rs+++ b/crates/gpui2/src/window.rs@@ -2170,6 +2170,9 @@ impl<'a, V: 'static> ViewContext<'a, V> {});}+ /// Set an input handler, such as [ElementInputHandler], which interfaces with the+ /// platform to receive textual input with proper integration with concerns such+ /// as IME interactions.pub fn handle_input(&mut self,focus_handle: &FocusHandle,