pub trait InputHandler: 'static {
Show 17 methods
// 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 methods
fn paste(&mut self, item: ClipboardItem, window: &mut Window, cx: &mut App) { ... }
fn set_selected_text_range(
&mut self,
_range_utf16: Range<usize>,
_window: &mut Window,
_cx: &mut App,
) { ... }
fn element_bounds(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> Option<Bounds<Pixels>> { ... }
fn text_length_utf16(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> Option<usize> { ... }
fn apple_press_and_hold_enabled(&mut self) -> bool { ... }
fn accepts_text_input(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> bool { ... }
fn text_input_editable_range(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> Option<Range<usize>> { ... }
fn prefers_ime_for_printable_keys(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> bool { ... }
fn text_input_configuration(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> TextInputConfiguration { ... }
}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 paste(&mut self, item: ClipboardItem, window: &mut Window, cx: &mut App)
fn paste(&mut self, item: ClipboardItem, window: &mut Window, cx: &mut App)
Insert a platform-initiated paste at the current selection.
Platforms that deliver paste as an input event rather than through an
application-defined action (e.g. the DOM paste event on web) call
this with the full clipboard contents. The default implementation
inserts only the plain-text portion of the item.
Sourcefn set_selected_text_range(
&mut self,
_range_utf16: Range<usize>,
_window: &mut Window,
_cx: &mut App,
)
fn set_selected_text_range( &mut self, _range_utf16: Range<usize>, _window: &mut Window, _cx: &mut App, )
Set the range of the user’s currently selected text.
This is the reverse data-flow direction from Self::selected_text_range:
platforms call it when the system text machinery moves the selection on the
application’s behalf — e.g. the user drags a system selection handle or
invokes Select All from system UI (iOS UITextInput setSelectedTextRange:,
Android InputConnection.setSelection).
range_utf16 is in terms of UTF-16 characters, from 0 to the length of the document
Sourcefn element_bounds(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> Option<Bounds<Pixels>>
fn element_bounds( &mut self, _window: &mut Window, _cx: &mut App, ) -> Option<Bounds<Pixels>>
Get the bounds of the focused text element in window coordinates, if known.
This is the pull counterpart to the PlatformWindow::update_ime_position
push: mobile platforms ask for the focused element’s geometry when they
need it (e.g. to frame system text-interaction UI overlaid on the focused
element).
Sourcefn text_length_utf16(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> Option<usize>
fn text_length_utf16( &mut self, _window: &mut Window, _cx: &mut App, ) -> Option<usize>
Get the length of the document in UTF-16 characters, if known.
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.
Sourcefn accepts_text_input(&mut self, _window: &mut Window, _cx: &mut App) -> bool
fn accepts_text_input(&mut self, _window: &mut Window, _cx: &mut App) -> bool
Returns whether this handler is accepting text input to be inserted.
Sourcefn text_input_editable_range(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> Option<Range<usize>>
fn text_input_editable_range( &mut self, _window: &mut Window, _cx: &mut App, ) -> Option<Range<usize>>
The contiguous range of text, in UTF-16 code units, that platform text input may read and edit around the current selection.
Platforms that mirror document text into an IME-editable buffer clamp
the mirrored window to this range, so multi-step IME edit gestures
(word deletion, autocorrect rewrites, suggestion picks) cannot reach
content outside it. The range should contain the current selection;
when it cannot (a selection spanning a region boundary), platforms
degrade the mirrored IME context rather than widening the range.
None places no bound.
Sourcefn prefers_ime_for_printable_keys(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> bool
fn prefers_ime_for_printable_keys( &mut self, _window: &mut Window, _cx: &mut App, ) -> bool
Returns whether printable keys should be routed to the IME before keybinding
matching when a non-ASCII input source (e.g. Japanese, Korean, Chinese IME)
is active. This prevents multi-stroke keybindings like jj from intercepting
keys that the IME should compose.
Defaults to false. The editor overrides this based on whether it expects
character input (e.g. Vim insert mode returns true, normal mode returns false).
The terminal keeps the default false so that raw keys reach the terminal process.
Sourcefn text_input_configuration(
&mut self,
_window: &mut Window,
_cx: &mut App,
) -> TextInputConfiguration
fn text_input_configuration( &mut self, _window: &mut Window, _cx: &mut App, ) -> TextInputConfiguration
Get this handler’s preferences for platform text assistance.
GPUI re-queries this every frame and forwards it to the platform window only when it changes, so implementations must be cheap and may vary the result with application state (e.g. with the cursor’s position).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".