Implement character index for point (#23989)
Fixes #22939 Fixes #23970 Supersedes https://github.com/zed-industries/zed/pull/23469 Release Notes: - Fixed a bug where Zed could crash with certain input sources on macOS --------- Co-authored-by: Louis Brunner <louis.brunner.fr@gmail.com> Co-authored-by: ben <ben@zed.dev>
This commit is contained in:
parent
7da60995cc
commit
cfe0932c0a
9 changed files with 221 additions and 129 deletions
|
@ -792,6 +792,14 @@ impl PlatformInputHandler {
|
|||
cx,
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn character_index_for_point(&mut self, point: Point<Pixels>) -> Option<usize> {
|
||||
self.cx
|
||||
.update(|window, cx| self.handler.character_index_for_point(point, window, cx))
|
||||
.ok()
|
||||
.flatten()
|
||||
}
|
||||
}
|
||||
|
||||
/// A struct representing a selection in a text buffer, in UTF16 characters.
|
||||
|
@ -882,6 +890,16 @@ pub trait InputHandler: 'static {
|
|||
cx: &mut App,
|
||||
) -> Option<Bounds<Pixels>>;
|
||||
|
||||
/// Get the character offset for the given point in terms of UTF16 characters
|
||||
///
|
||||
/// Corresponds to [characterIndexForPoint:](https://developer.apple.com/documentation/appkit/nstextinputclient/characterindex(for:))
|
||||
fn character_index_for_point(
|
||||
&mut self,
|
||||
point: Point<Pixels>,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> Option<usize>;
|
||||
|
||||
/// 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue