Fix clipping at end of line in vim mode with inlay hints (#23975)
Closes #23877 Co-Authored-By: Ben <ben@zed.dev> Co-Authored-By: Michael <michael@zed.dev> Release Notes: - vim: Fix navigating to end of line with inlay hints --------- Co-authored-by: Ben <ben@zed.dev> Co-authored-by: Michael <michael@zed.dev>
This commit is contained in:
parent
5914ccdc51
commit
cb15753694
2 changed files with 47 additions and 12 deletions
|
@ -1068,13 +1068,15 @@ impl DisplaySnapshot {
|
||||||
DisplayPoint(self.block_snapshot.clip_point(point.0, bias))
|
DisplayPoint(self.block_snapshot.clip_point(point.0, bias))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clip_at_line_end(&self, point: DisplayPoint) -> DisplayPoint {
|
pub fn clip_at_line_end(&self, display_point: DisplayPoint) -> DisplayPoint {
|
||||||
let mut point = point.0;
|
let mut point = self.display_point_to_point(display_point, Bias::Left);
|
||||||
if point.column == self.line_len(DisplayRow(point.row)) {
|
|
||||||
point.column = point.column.saturating_sub(1);
|
if point.column != self.buffer_snapshot.line_len(MultiBufferRow(point.row)) {
|
||||||
point = self.block_snapshot.clip_point(point, Bias::Left);
|
return display_point;
|
||||||
}
|
}
|
||||||
DisplayPoint(point)
|
point.column = point.column.saturating_sub(1);
|
||||||
|
point = self.buffer_snapshot.clip_point(point, Bias::Left);
|
||||||
|
self.point_to_display_point(point, Bias::Left)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Fold>
|
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Fold>
|
||||||
|
|
|
@ -2761,6 +2761,8 @@ mod test {
|
||||||
};
|
};
|
||||||
use editor::display_map::Inlay;
|
use editor::display_map::Inlay;
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
|
use language::Point;
|
||||||
|
use multi_buffer::MultiBufferRow;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_start_end_of_paragraph(cx: &mut gpui::TestAppContext) {
|
async fn test_start_end_of_paragraph(cx: &mut gpui::TestAppContext) {
|
||||||
|
@ -3452,4 +3454,35 @@ mod test {
|
||||||
Mode::Normal,
|
Mode::Normal,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_clipping_with_inlay_hints_end_of_line(cx: &mut gpui::TestAppContext) {
|
||||||
|
let mut cx = VimTestContext::new(cx, true).await;
|
||||||
|
|
||||||
|
cx.set_state(
|
||||||
|
indoc! {"
|
||||||
|
ˇstruct Foo {
|
||||||
|
|
||||||
|
}
|
||||||
|
"},
|
||||||
|
Mode::Normal,
|
||||||
|
);
|
||||||
|
cx.update_editor(|editor, _window, cx| {
|
||||||
|
let snapshot = editor.buffer().read(cx).snapshot(cx);
|
||||||
|
let end_of_line =
|
||||||
|
snapshot.anchor_after(Point::new(0, snapshot.line_len(MultiBufferRow(0))));
|
||||||
|
let inlay_text = " hint";
|
||||||
|
let inlay = Inlay::inline_completion(1, end_of_line, inlay_text);
|
||||||
|
editor.splice_inlays(vec![], vec![inlay], cx);
|
||||||
|
});
|
||||||
|
cx.simulate_keystrokes("$");
|
||||||
|
cx.assert_state(
|
||||||
|
indoc! {"
|
||||||
|
struct Foo ˇ{
|
||||||
|
|
||||||
|
}
|
||||||
|
"},
|
||||||
|
Mode::Normal,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue