diff options
author | Blaž Hrastnik | 2021-02-22 06:50:41 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-02-22 08:02:32 +0000 |
commit | 6cfb1acb9d1456e854a2c44ee8fc057f45b29ea9 (patch) | |
tree | 13cff77a4a8fe007b6cd6eff3af863c7cdeffe9e /helix-term | |
parent | 33c67f138835d4407e076ebcf2d29322fda44114 (diff) |
commands: Implement expand_selection.
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 13 | ||||
-rw-r--r-- | helix-term/src/keymap.rs | 3 |
2 files changed, 15 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index c048ff9a..c37c0710 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1,6 +1,7 @@ use helix_core::{ comment, graphemes, indent::TAB_WIDTH, + object, regex::{self, Regex}, register, selection, state::{Direction, Granularity, State}, @@ -1023,3 +1024,15 @@ pub fn toggle_comments(cx: &mut Context) { doc.apply(&transaction); } + +// tree sitter node selection + +pub fn expand_selection(cx: &mut Context) { + let doc = cx.doc(); + + if let Some(syntax) = &doc.syntax { + let text = doc.text().slice(..); + let selection = object::expand_selection(syntax, text, doc.selection()); + doc.set_selection(selection); + } +} diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 69c8e48c..81665bbe 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -164,10 +164,11 @@ pub fn default() -> Keymaps { vec![alt!('s')] => commands::split_selection_on_newline, vec![shift!('S')] => commands::split_selection, vec![key!(';')] => commands::collapse_selection, - // TODO should be alt(;) vec![alt!(';')] => commands::flip_selections, vec![key!('%')] => commands::select_all, vec![key!('x')] => commands::select_line, + // TODO: figure out what key to use + vec![key!('[')] => commands::expand_selection, vec![key!('/')] => commands::search, vec![key!('n')] => commands::search_next, vec![key!('*')] => commands::search_selection, |