From 73c92a0bc1499f02092a7425c45d4992f4e573a1 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Mon, 22 Mar 2021 17:58:49 +0900 Subject: Implement m / match_brackets (using tree sitter). --- helix-term/src/commands.rs | 14 +++++++++++++- helix-term/src/keymap.rs | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'helix-term') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b9ee933d..3f0e32a0 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1,5 +1,5 @@ use helix_core::{ - comment, coords_at_pos, graphemes, + comment, coords_at_pos, graphemes, match_brackets, movement::{self, Direction}, object, pos_at_coords, regex::{self, Regex}, @@ -1592,3 +1592,15 @@ pub fn expand_selection(cx: &mut Context) { doc.set_selection(selection); } } + +pub fn match_brackets(cx: &mut Context) { + let mut doc = cx.doc(); + + if let Some(syntax) = doc.syntax() { + let pos = doc.selection().cursor(); + if let Some(pos) = match_brackets::find(syntax, doc.text(), pos) { + let selection = Selection::point(pos); + doc.set_selection(selection); + }; + } +} diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index 1f34aa9e..bd1b31ef 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -182,6 +182,9 @@ pub fn default() -> Keymaps { // or select mode X? // extend_to_whole_line, crop_to_whole_line + + key!('m') => commands::match_brackets, + // TODO: refactor into // key!('m') => commands::select_to_matching, // key!('M') => commands::back_select_to_matching, // select mode extend equivalents -- cgit v1.2.3-70-g09d2