aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorIvan Tham2021-06-05 10:15:50 +0000
committerBlaž Hrastnik2021-06-06 12:30:18 +0000
commit40744ce8356cb9307f8cb9b2adf2c57b80b1ef9f (patch)
tree3fc2a99ecdeb9e027d7c093c660e8863622b46b2 /helix-term/src
parentaa8a8baeeb06cd94ed6329c535483f30835ec426 (diff)
Add ctrl-w in insert mode
It seemed to panic when I pressed too many times, but that is from lsp side.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs20
-rw-r--r--helix-term/src/keymap.rs1
2 files changed, 18 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index c88a5eee..f340da91 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -3,8 +3,8 @@ use helix_core::{
movement::{self, Direction},
object, pos_at_coords,
regex::{self, Regex},
- register, search, selection, Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection,
- SmallVec, Tendril, Transaction,
+ register, search, selection, words, Change, ChangeSet, Position, Range, Rope, RopeSlice,
+ Selection, SmallVec, Tendril, Transaction,
};
use helix_view::{
@@ -1782,7 +1782,6 @@ pub mod insert {
pub fn delete_char_forward(cx: &mut Context) {
let count = cx.count;
- let doc = cx.doc();
let (view, doc) = cx.current();
let text = doc.text().slice(..);
let transaction =
@@ -1795,6 +1794,21 @@ pub mod insert {
});
doc.apply(&transaction, view.id);
}
+
+ pub fn delete_word_backward(cx: &mut Context) {
+ let count = cx.count;
+ let (view, doc) = cx.current();
+ let text = doc.text().slice(..);
+ let transaction =
+ Transaction::change_by_selection(doc.text(), doc.selection(view.id), |range| {
+ (
+ words::nth_prev_word_boundary(text, range.head, count),
+ range.head,
+ None,
+ )
+ });
+ doc.apply(&transaction, view.id);
+ }
}
// Undo / Redo
diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs
index e51dfbc5..6ef53915 100644
--- a/helix-term/src/keymap.rs
+++ b/helix-term/src/keymap.rs
@@ -360,6 +360,7 @@ pub fn default() -> Keymaps {
} => commands::insert::insert_tab,
ctrl!('x') => commands::completion,
+ ctrl!('w') => commands::insert::delete_word_backward,
),
)
}