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
5 changes: 2 additions & 3 deletions assets/keymaps/vim.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,8 @@
">": "vim::Indent",
"<": "vim::Outdent",
"=": "vim::AutoIndent",
"g u": "vim::PushLowercase",
"g shift-u": "vim::PushUppercase",
"g ~": "vim::PushOppositeCase",
"`": "vim::ConvertToLowerCase",
"alt-`": "vim::ConvertToUpperCase",
"g q": "vim::PushRewrap",
"g w": "vim::PushRewrap",
"insert": "vim::InsertBefore",
Expand Down
24 changes: 17 additions & 7 deletions crates/vim/src/normal/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,10 @@ impl Vim {

Mode::HelixNormal | Mode::HelixSelect => {
if selection.is_empty() {
// Handle empty selection by operating on the whole word
let (word_range, _) = snapshot.surrounding_word(selection.start, false);
let word_start = snapshot.offset_to_point(word_range.start);
let word_end = snapshot.offset_to_point(word_range.end);
ranges.push(word_start..word_end);
// Handle empty selection by operating on single character
let start = selection.start;
let end = snapshot.clip_point(start + Point::new(0, 1), Bias::Right);
ranges.push(start..end);
cursor_positions.push(selection.start..selection.start);
} else {
ranges.push(selection.start..selection.end);
Expand Down Expand Up @@ -445,15 +444,26 @@ mod test {
cx.simulate_keystrokes("~");
cx.assert_state("«HELLO WORLDˇ»", Mode::HelixNormal);

// Cursor-only (empty) selection
// Cursor-only (empty) selection - switch case
cx.set_state("The ˇquick brown", Mode::HelixNormal);
cx.simulate_keystrokes("~");
cx.assert_state("The ˇQUICK brown", Mode::HelixNormal);
cx.assert_state("The ˇQuick brown", Mode::HelixNormal);
cx.simulate_keystrokes("~");
cx.assert_state("The ˇquick brown", Mode::HelixNormal);

// Cursor-only (empty) selection - switch to uppercase and lowercase explicitly
cx.set_state("The ˇquick brown", Mode::HelixNormal);
cx.simulate_keystrokes("alt-`");
cx.assert_state("The ˇQuick brown", Mode::HelixNormal);
cx.simulate_keystrokes("`");
cx.assert_state("The ˇquick brown", Mode::HelixNormal);

// With `e` motion (which extends selection to end of word in Helix)
cx.set_state("The ˇquick brown fox", Mode::HelixNormal);
cx.simulate_keystrokes("e");
cx.simulate_keystrokes("~");
cx.assert_state("The «QUICKˇ» brown fox", Mode::HelixNormal);

// Cursor-only
}
}
Loading