From 5feda0c81ba1cc13817e19464186f5f683f7efa2 Mon Sep 17 00:00:00 2001 From: vaw Date: Mon, 14 Sep 2026 00:26:23 +0200 Subject: [PATCH 1/2] Support vim-like guessing of clipboard target shape --- crates/modalkit/src/editing/store/register.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/modalkit/src/editing/store/register.rs b/crates/modalkit/src/editing/store/register.rs index 95c929e..52f7139 100644 --- a/crates/modalkit/src/editing/store/register.rs +++ b/crates/modalkit/src/editing/store/register.rs @@ -56,6 +56,22 @@ mod clipboard { } } +/// Guess the target shape based on string format +/// +/// If the text ends on a newline, assume it is [`LineWise`](`TargetShape::LineWise`) and else +/// [`CharWise`](`TargetShape::CharWise`). +/// +/// This copies what vim does +/// [here](https://github.com/vim/vim/blob/2ec2a612c7ac9315a17d70f6a2a5ea89ddaea854/src/register.c#L3246-L3248). +fn with_guessed_clipboard_shape(text: String) -> RegisterCell { + let shape = match text.as_bytes().last() { + Some(b'\n') | Some(b'\r') => TargetShape::LineWise, + _ => TargetShape::CharWise, + }; + + RegisterCell::new(shape, EditRope::from(text)) +} + #[cfg(feature = "clipboard")] use self::clipboard::*; @@ -306,7 +322,7 @@ impl RegisterStore { } if let Ok(text) = get_primary(clipboard).text() { - RegisterCell::from(EditRope::from(text)) + with_guessed_clipboard_shape(text) } else { RegisterCell::default() } @@ -325,7 +341,7 @@ impl RegisterStore { } if let Ok(text) = get_clipboard(clipboard).text() { - RegisterCell::from(EditRope::from(text)) + with_guessed_clipboard_shape(text) } else { RegisterCell::default() } From b00eda7ea9a65086edb1d1f4348ac0f6c71bac77 Mon Sep 17 00:00:00 2001 From: Ulyssa Date: Mon, 14 Sep 2026 18:32:28 -0400 Subject: [PATCH 2/2] fixup clippy --- crates/modalkit/src/editing/store/register.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/modalkit/src/editing/store/register.rs b/crates/modalkit/src/editing/store/register.rs index 52f7139..7f89e96 100644 --- a/crates/modalkit/src/editing/store/register.rs +++ b/crates/modalkit/src/editing/store/register.rs @@ -63,6 +63,7 @@ mod clipboard { /// /// This copies what vim does /// [here](https://github.com/vim/vim/blob/2ec2a612c7ac9315a17d70f6a2a5ea89ddaea854/src/register.c#L3246-L3248). +#[cfg(feature = "clipboard")] fn with_guessed_clipboard_shape(text: String) -> RegisterCell { let shape = match text.as_bytes().last() { Some(b'\n') | Some(b'\r') => TargetShape::LineWise,