From 2bd2e9b18ccc7f7312481c47e5303d64445ab299 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 4 May 2026 10:40:39 +0200 Subject: [PATCH] vim: Fix panic when pasting in read-only editor --- crates/vim/src/helix/paste.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/vim/src/helix/paste.rs b/crates/vim/src/helix/paste.rs index c43281421462ee..c8db0722c2c147 100644 --- a/crates/vim/src/helix/paste.rs +++ b/crates/vim/src/helix/paste.rs @@ -28,6 +28,10 @@ impl Vim { // (none of the other helix_ methods call it) self.update_editor(cx, |vim, editor, cx| { + if editor.read_only(cx) { + return; + } + editor.transact(window, cx, |editor, window, cx| { editor.set_clip_at_line_ends(false, cx); @@ -201,6 +205,19 @@ mod test { cx.assert_state("«Xˇ»\n«Xˇ»\n«Xˇ»\nend", Mode::HelixNormal); } + #[gpui::test] + async fn test_read_only_paste(cx: &mut gpui::TestAppContext) { + let mut cx = VimTestContext::new(cx, true).await; + cx.enable_helix(); + cx.set_state("aˇb", Mode::HelixNormal); + cx.write_to_clipboard(ClipboardItem::new_string("clipboard".to_string())); + cx.update_editor(|editor, _window, _cx| editor.set_read_only(true)); + + cx.simulate_keystrokes("p"); + + cx.assert_state("aˇb", Mode::HelixNormal); + } + #[gpui::test] async fn test_paste(cx: &mut gpui::TestAppContext) { let mut cx = VimTestContext::new(cx, true).await;