From 36e7e2133fe1d472600cfd935b8046b8d50146c2 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Tue, 29 Sep 2020 01:01:27 +0900 Subject: Split selection on regex, fix InputEdit generation. --- helix-view/src/commands.rs | 11 +++++++++++ helix-view/src/keymap.rs | 4 ++++ 2 files changed, 15 insertions(+) (limited to 'helix-view/src') diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index d868a17c..fc18e3a7 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -1,8 +1,11 @@ use helix_core::{ graphemes, + regex::Regex, + selection, state::{Direction, Granularity, Mode, State}, Range, Selection, Tendril, Transaction, }; +use once_cell::sync::Lazy; use crate::view::View; @@ -144,6 +147,14 @@ pub fn extend_line_down(view: &mut View, count: usize) { .extend_selection(Direction::Forward, Granularity::Line, count); } +pub fn split_selection_on_newline(view: &mut View, _count: usize) { + let text = &view.state.doc.slice(..); + // only compile the regex once + static REGEX: Lazy = Lazy::new(|| Regex::new(r"\n").unwrap()); + // TODO: use a transaction + view.state.selection = selection::split_on_matches(text, view.state.selection(), ®EX) +} + pub fn delete_selection(view: &mut View, _count: usize) { let transaction = Transaction::change_by_selection(&view.state, |range| (range.from(), range.to(), None)); diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index 750f1a5f..078f2bf1 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -174,6 +174,10 @@ pub fn default() -> Keymaps { code: KeyCode::Char('c'), modifiers: Modifiers::NONE }] => commands::change_selection as Command, + vec![Key { + code: KeyCode::Char('s'), + modifiers: Modifiers::NONE + }] => commands::split_selection_on_newline as Command, vec![Key { code: KeyCode::Esc, modifiers: Modifiers::NONE -- cgit v1.2.3-70-g09d2