summaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-09-28 16:00:35 +0000
committerBlaž Hrastnik2020-09-28 16:00:35 +0000
commit3020077da8efbf914a9cb0a2cbb50362d339a39a (patch)
treeaf8eaf9c016ac5116f6349a6b5ebb79e77f8efb5 /helix-view
parentfbe313779e83728b7dca7925df722c7fb4228d98 (diff)
Extend selection commands.
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/Cargo.toml5
-rw-r--r--helix-view/src/commands.rs40
-rw-r--r--helix-view/src/keymap.rs32
3 files changed, 75 insertions, 2 deletions
diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml
index 37957625..0d887474 100644
--- a/helix-view/Cargo.toml
+++ b/helix-view/Cargo.toml
@@ -10,9 +10,10 @@ edition = "2018"
term = ["tui", "crossterm"]
[dependencies]
-anyhow = "1.0.32"
+anyhow = "1"
helix-core = { path = "../helix-core" }
# Conversion traits
-tui = { version = "0.10.0", default-features = false, features = ["crossterm"], optional = true}
+tui = { version = "0.11", default-features = false, features = ["crossterm"], optional = true}
crossterm = { version = "0.17", features = ["event-stream"], optional = true}
+once_cell = "1.4"
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs
index 42390c23..d868a17c 100644
--- a/helix-view/src/commands.rs
+++ b/helix-view/src/commands.rs
@@ -115,6 +115,46 @@ pub fn move_next_word_end(view: &mut View, count: usize) {
// avoid select by default by having a visual mode switch that makes movements into selects
+pub fn extend_char_left(view: &mut View, count: usize) {
+ // TODO: use a transaction
+ let selection = view
+ .state
+ .extend_selection(Direction::Backward, Granularity::Character, count);
+ view.state.selection = selection;
+}
+
+pub fn extend_char_right(view: &mut View, count: usize) {
+ // TODO: use a transaction
+ view.state.selection =
+ view.state
+ .extend_selection(Direction::Forward, Granularity::Character, count);
+}
+
+pub fn extend_line_up(view: &mut View, count: usize) {
+ // TODO: use a transaction
+ view.state.selection =
+ view.state
+ .extend_selection(Direction::Backward, Granularity::Line, count);
+}
+
+pub fn extend_line_down(view: &mut View, count: usize) {
+ // TODO: use a transaction
+ view.state.selection =
+ view.state
+ .extend_selection(Direction::Forward, Granularity::Line, count);
+}
+
+pub fn delete_selection(view: &mut View, _count: usize) {
+ let transaction =
+ Transaction::change_by_selection(&view.state, |range| (range.from(), range.to(), None));
+ transaction.apply(&mut view.state);
+}
+
+pub fn change_selection(view: &mut View, count: usize) {
+ delete_selection(view, count);
+ insert_mode(view, count);
+}
+
// insert mode:
// first we calculate the correct cursors/selections
// then we just append at each cursor
diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs
index 5d9b6653..750f1a5f 100644
--- a/helix-view/src/keymap.rs
+++ b/helix-view/src/keymap.rs
@@ -7,7 +7,9 @@ use std::collections::HashMap;
// normal = {
// q = record_macro
// w = (next) word
+// W = next WORD
// e = end of word
+// E = end of WORD
// r =
// t = 'till char
// y = yank
@@ -55,6 +57,12 @@ use std::collections::HashMap;
// & = align cursor
// ? = extend to next given regex match (alt = to prev)
//
+// in kakoune these are alt-h alt-l / gh gl
+// select from curs to begin end / move curs to begin end
+// 0 = start of line
+// ^ = start of line (first non blank char)
+// $ = end of line
+//
// z = save selections
// Z = restore selections
// x = select line
@@ -111,6 +119,22 @@ pub fn default() -> Keymaps {
modifiers: Modifiers::NONE
}] => commands::move_char_right as Command,
vec![Key {
+ code: KeyCode::Char('H'),
+ modifiers: Modifiers::SHIFT
+ }] => commands::extend_char_left as Command,
+ vec![Key {
+ code: KeyCode::Char('J'),
+ modifiers: Modifiers::SHIFT
+ }] => commands::extend_line_down as Command,
+ vec![Key {
+ code: KeyCode::Char('K'),
+ modifiers: Modifiers::SHIFT
+ }] => commands::extend_line_up as Command,
+ vec![Key {
+ code: KeyCode::Char('L'),
+ modifiers: Modifiers::SHIFT
+ }] => commands::extend_char_right as Command,
+ vec![Key {
code: KeyCode::Char('w'),
modifiers: Modifiers::NONE
}] => commands::move_next_word_start as Command,
@@ -143,6 +167,14 @@ pub fn default() -> Keymaps {
modifiers: Modifiers::NONE
}] => commands::open_below as Command,
vec![Key {
+ code: KeyCode::Char('d'),
+ modifiers: Modifiers::NONE
+ }] => commands::delete_selection as Command,
+ vec![Key {
+ code: KeyCode::Char('c'),
+ modifiers: Modifiers::NONE
+ }] => commands::change_selection as Command,
+ vec![Key {
code: KeyCode::Esc,
modifiers: Modifiers::NONE
}] => commands::normal_mode as Command,