IME · the candidate box clamps to the last layout: asked before the next one, it found nothing and macOS put it in the screen's corner (#7)
This commit is contained in:
1 parent
33df23c02a
commit
152d881f4f
3 files changed
+26
-11
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use gpui::{AppContext, Context, IntoElement, Render, TestAppContext, Window};
|
||||
use gpui::{AppContext, Context, EntityInputHandler, IntoElement, Render, TestAppContext, Window};
|
||||
|
||||
use super::setup;
|
||||
use crate::forms::{TextInput, UnitInput};
|
||||
@@ -45,3 +45,24 @@ fn a_unit_gone_from_its_list_keeps_the_field(cx: &mut TestAppContext) {
|
||||
cx.run_until_parked();
|
||||
assert!(cx.debug_bounds("number-root").is_some());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn an_ime_finds_its_composition_before_the_next_layout(cx: &mut TestAppContext) {
|
||||
let (fields, cx) = super::open(1, false, cx);
|
||||
let field = fields[0].clone();
|
||||
super::focus(&field, cx);
|
||||
field.update(cx, |input, cx| input.set_text("abc", cx));
|
||||
cx.run_until_parked();
|
||||
let laid = field
|
||||
.read_with(cx, |input, _| input.bounds_for(3))
|
||||
.expect("laid out");
|
||||
let asked = cx.update(|window, cx| {
|
||||
field.update(cx, |input, cx| {
|
||||
input.replace_and_mark_text_in_range(None, "n", None, window, cx);
|
||||
let at = gpui::Bounds::new(laid.origin, gpui::size(gpui::px(200.), laid.size.height));
|
||||
input.bounds_for_range(3..4, at, window, cx)
|
||||
})
|
||||
});
|
||||
let asked = asked.expect("the candidate box has a place");
|
||||
assert_eq!(asked.origin, laid.origin, "at the caret, on its line");
|
||||
}
|
||||
@@ -126,19 +126,13 @@ impl EntityInputHandler for TextInput {
|
||||
fn bounds_for_range(
|
||||
&mut self,
|
||||
range_utf16: Range<usize>,
|
||||
bounds: Bounds<Pixels>,
|
||||
_: Bounds<Pixels>,
|
||||
_: &mut Window,
|
||||
_: &mut Context<Self>,
|
||||
) -> Option<Bounds<Pixels>> {
|
||||
let range = self.range_from_utf16(&range_utf16);
|
||||
let line_height = self.layout.as_ref()?.line_height;
|
||||
let start = self.position_for(self.display_offset(range.start))?;
|
||||
let end = self.position_for(self.display_offset(range.end))?;
|
||||
let origin = bounds.origin - self.scroll;
|
||||
Some(Bounds::from_corners(
|
||||
origin + start,
|
||||
origin + gpui::point(end.x, end.y + line_height),
|
||||
))
|
||||
let (start, end) = (self.bounds_for(range.start)?, self.bounds_for(range.end)?);
|
||||
Some(Bounds::from_corners(start.origin, end.bottom_left()))
|
||||
}
|
||||
|
||||
fn character_index_for_point(
|
||||
|
||||
Reference in new issue
Block a user