Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6047,7 +6047,7 @@ impl Editor {
pub fn text_layout_details(&self, window: &mut Window, cx: &mut App) -> TextLayoutDetails {
TextLayoutDetails {
text_system: window.text_system().clone(),
editor_style: self.style.clone().unwrap(),
editor_style: self.style.clone().unwrap_or_else(|| self.create_style(cx)),
rem_size: window.rem_size(),
scroll_anchor: self.scroll_manager.shared_scroll_anchor(cx),
visible_rows: self.visible_line_count(),
Expand Down
55 changes: 55 additions & 0 deletions crates/vim/src/helix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2960,6 +2960,61 @@ mod test {
cx.assert_state("«ˇone» two three", Mode::HelixSelect);
}

// Regression test for ZED-758: helix motions called
// `Editor::text_layout_details` on an editor whose `style` had never
// been set, panicking on `unwrap()`.
#[gpui::test]
async fn test_helix_motion_on_unrendered_editor(cx: &mut gpui::TestAppContext) {
use editor::{Editor, EditorMode, SelectionEffects};
use multi_buffer::{MultiBuffer, MultiBufferOffset};

VimTestContext::init(cx);
cx.update(|cx| {
VimTestContext::init_keybindings(true, cx);
SettingsStore::update_global(cx, |store, cx| {
store.update_user_settings(cx, |s| {
s.vim_mode = Some(true);
s.helix_mode = Some(true);
});
});
});

let cx = cx.add_empty_window();

let editor = cx.update(|window, cx| {
use gpui::AppContext as _;
let buffer = MultiBuffer::build_simple("one two three", cx);
cx.new(|cx| {
let mut editor = Editor::new(EditorMode::full(), buffer, None, window, cx);
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select_ranges([MultiBufferOffset(4)..MultiBufferOffset(4)])
});
editor
})
});

let vim = editor
.read_with(cx, |editor, _| editor.addon::<VimAddon>().cloned())
.expect("VimAddon should be auto-attached to new editors when vim mode is enabled");

cx.update(|window, cx| {
vim.entity.update(cx, |vim, cx| {
vim.switch_mode(Mode::HelixNormal, true, window, cx);
vim.helix_move_and_collapse(crate::motion::Motion::Left, None, window, cx);
});
});

let cursor_offset = cx.update(|_, cx| {
editor.update(cx, |editor, cx| {
editor
.selections
.newest::<MultiBufferOffset>(&editor.display_snapshot(cx))
.head()
})
});
assert_eq!(cursor_offset, MultiBufferOffset(3));
}

#[gpui::test]
async fn test_helix_select_regex(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
Expand Down
Loading