Skip to content
Merged
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
21 changes: 19 additions & 2 deletions crates/modalkit/src/editing/store/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ 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).
#[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,
_ => TargetShape::CharWise,
};

RegisterCell::new(shape, EditRope::from(text))
}

#[cfg(feature = "clipboard")]
use self::clipboard::*;

Expand Down Expand Up @@ -306,7 +323,7 @@ impl RegisterStore {
}

if let Ok(text) = get_primary(clipboard).text() {
RegisterCell::from(EditRope::from(text))
with_guessed_clipboard_shape(text)
} else {
RegisterCell::default()
}
Expand All @@ -325,7 +342,7 @@ impl RegisterStore {
}

if let Ok(text) = get_clipboard(clipboard).text() {
RegisterCell::from(EditRope::from(text))
with_guessed_clipboard_shape(text)
} else {
RegisterCell::default()
}
Expand Down
Loading