pub trait InputHandler: 'static {
// Required methods
fn selected_text_range(
&mut self,
ignore_disabled_input: bool,
window: &mut Window,
cx: &mut App,
) -> Option<UTF16Selection>;
fn marked_text_range(
&mut self,
window: &mut Window,
cx: &mut App,
) -> Option<Range<usize>>;
fn text_for_range(
&mut self,
range_utf16: Range<usize>,
adjusted_range: &mut Option<Range<usize>>,
window: &mut Window,
cx: &mut App,
) -> Option<String>;
fn replace_text_in_range(
&mut self,
replacement_range: Option<Range<usize>>,
text: &str,
window: &mut Window,
cx: &mut App,
);
fn replace_and_mark_text_in_range(
&mut self,
range_utf16: Option<Range<usize>>,
new_text: &str,
new_selected_range: Option<Range<usize>>,
window: &mut Window,
cx: &mut App,
);
fn unmark_text(&mut self, window: &mut Window, cx: &mut App);
fn bounds_for_range(
&mut self,
range_utf16: Range<usize>,
window: &mut Window,
cx: &mut App,
) -> Option<Bounds<Pixels>>;
fn character_index_for_point(
&mut self,
point: Point<Pixels>,
window: &mut Window,
cx: &mut App,
) -> Option<usize>;
// Provided method
fn apple_press_and_hold_enabled(&mut self) -> bool { ... }
}Expand description
Zed’s interface for handling text input from the platform’s IME system This is currently a 1:1 exposure of the NSTextInputClient API:
https://developer.apple.com/documentation/appkit/nstextinputclient
Required Methods§
Sourcefn selected_text_range(
&mut self,
ignore_disabled_input: bool,
window: &mut Window,
cx: &mut App,
) -> Option<UTF16Selection>
fn selected_text_range( &mut self, ignore_disabled_input: bool, window: &mut Window, cx: &mut App, ) -> Option<UTF16Selection>
Get the range of the user’s currently selected text, if any Corresponds to selectedRange()
Return value is in terms of UTF-16 characters, from 0 to the length of the document
Sourcefn marked_text_range(
&mut self,
window: &mut Window,
cx: &mut App,
) -> Option<Range<usize>>
fn marked_text_range( &mut self, window: &mut Window, cx: &mut App, ) -> Option<Range<usize>>
Get the range of the currently marked text, if any Corresponds to markedRange()
Return value is in terms of UTF-16 characters, from 0 to the length of the document
Sourcefn text_for_range(
&mut self,
range_utf16: Range<usize>,
adjusted_range: &mut Option<Range<usize>>,
window: &mut Window,
cx: &mut App,
) -> Option<String>
fn text_for_range( &mut self, range_utf16: Range<usize>, adjusted_range: &mut Option<Range<usize>>, window: &mut Window, cx: &mut App, ) -> Option<String>
Get the text for the given document range in UTF-16 characters Corresponds to attributedSubstring(forProposedRange: actualRange:)
range_utf16 is in terms of UTF-16 characters
Sourcefn replace_text_in_range(
&mut self,
replacement_range: Option<Range<usize>>,
text: &str,
window: &mut Window,
cx: &mut App,
)
fn replace_text_in_range( &mut self, replacement_range: Option<Range<usize>>, text: &str, window: &mut Window, cx: &mut App, )
Replace the text in the given document range with the given text Corresponds to insertText(_:replacementRange:)
replacement_range is in terms of UTF-16 characters
Sourcefn replace_and_mark_text_in_range(
&mut self,
range_utf16: Option<Range<usize>>,
new_text: &str,
new_selected_range: Option<Range<usize>>,
window: &mut Window,
cx: &mut App,
)
fn replace_and_mark_text_in_range( &mut self, range_utf16: Option<Range<usize>>, new_text: &str, new_selected_range: Option<Range<usize>>, window: &mut Window, cx: &mut App, )
Replace the text in the given document range with the given text, and mark the given text as part of an IME ‘composing’ state Corresponds to setMarkedText(_:selectedRange:replacementRange:)
range_utf16 is in terms of UTF-16 characters new_selected_range is in terms of UTF-16 characters
Sourcefn unmark_text(&mut self, window: &mut Window, cx: &mut App)
fn unmark_text(&mut self, window: &mut Window, cx: &mut App)
Remove the IME ‘composing’ state from the document Corresponds to unmarkText()
Sourcefn bounds_for_range(
&mut self,
range_utf16: Range<usize>,
window: &mut Window,
cx: &mut App,
) -> Option<Bounds<Pixels>>
fn bounds_for_range( &mut self, range_utf16: Range<usize>, window: &mut Window, cx: &mut App, ) -> Option<Bounds<Pixels>>
Get the bounds of the given document range in screen coordinates Corresponds to firstRect(forCharacterRange:actualRange:)
This is used for positioning the IME candidate window
Sourcefn character_index_for_point(
&mut self,
point: Point<Pixels>,
window: &mut Window,
cx: &mut App,
) -> Option<usize>
fn character_index_for_point( &mut self, point: Point<Pixels>, window: &mut Window, cx: &mut App, ) -> Option<usize>
Get the character offset for the given point in terms of UTF16 characters
Corresponds to characterIndexForPoint:
Provided Methods§
Sourcefn apple_press_and_hold_enabled(&mut self) -> bool
fn apple_press_and_hold_enabled(&mut self) -> bool
Allows a given input context to opt into getting raw key repeats instead of sending these to the platform. TODO: Ideally we should be able to set ApplePressAndHoldEnabled in NSUserDefaults (which is how iTerm does it) but it doesn’t seem to work for me.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".