Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs53
1 files changed, 28 insertions, 25 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 9b203092..6cda93dc 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -38,7 +38,7 @@ use helix_core::{
textobject,
unicode::width::UnicodeWidthChar,
visual_offset_from_block, Deletion, LineEnding, Position, Range, Rope, RopeGraphemes,
- RopeReader, RopeSlice, Selection, SmallVec, Tendril, Transaction,
+ RopeReader, RopeSlice, Selection, SmallVec, Syntax, Tendril, Transaction,
};
use helix_view::{
document::{FormatterError, Mode, SCRATCH_BUFFER_NAME},
@@ -4976,17 +4976,23 @@ pub fn extend_parent_node_start(cx: &mut Context) {
move_node_bound_impl(cx, Direction::Backward, Movement::Extend)
}
+fn select_all_impl<F>(editor: &mut Editor, select_fn: F)
+where
+ F: Fn(&Syntax, RopeSlice, Selection) -> Selection,
+{
+ let (view, doc) = current!(editor);
+
+ if let Some(syntax) = doc.syntax() {
+ let text = doc.text().slice(..);
+ let current_selection = doc.selection(view.id);
+ let selection = select_fn(syntax, text, current_selection.clone());
+ doc.set_selection(view.id, selection);
+ }
+}
+
fn select_all_siblings(cx: &mut Context) {
let motion = |editor: &mut Editor| {
- let (view, doc) = current!(editor);
-
- if let Some(syntax) = doc.syntax() {
- let text = doc.text().slice(..);
- let current_selection = doc.selection(view.id);
- let selection =
- object::select_all_siblings(syntax.tree(), text, current_selection.clone());
- doc.set_selection(view.id, selection);
- }
+ select_all_impl(editor, object::select_all_siblings);
};
cx.editor.apply_motion(motion);
@@ -4994,19 +5000,10 @@ fn select_all_siblings(cx: &mut Context) {
fn select_all_children(cx: &mut Context) {
let motion = |editor: &mut Editor| {
- let (view, doc) = current!(editor);
-
- if let Some(syntax) = doc.syntax() {
- let text = doc.text().slice(..);
- let current_selection = doc.selection(view.id);
- let selection =
- object::select_all_children(syntax.tree(), text, current_selection.clone());
- doc.set_selection(view.id, selection);
- }
+ select_all_impl(editor, object::select_all_children);
};
- motion(cx.editor);
- cx.editor.last_motion = Some(Motion(Box::new(motion)));
+ cx.editor.apply_motion(motion);
}
fn match_brackets(cx: &mut Context) {
@@ -6040,7 +6037,10 @@ fn jump_to_label(cx: &mut Context, labels: Vec<Range>, behaviour: Movement) {
let doc = doc.id();
cx.on_next_key(move |cx, event| {
let alphabet = &cx.editor.config().jump_label_alphabet;
- let Some(i ) = event.char().and_then(|ch| alphabet.iter().position(|&it| it == ch)) else {
+ let Some(i) = event
+ .char()
+ .and_then(|ch| alphabet.iter().position(|&it| it == ch))
+ else {
doc_mut!(cx.editor, &doc).remove_jump_labels(view);
return;
};
@@ -6053,7 +6053,10 @@ fn jump_to_label(cx: &mut Context, labels: Vec<Range>, behaviour: Movement) {
cx.on_next_key(move |cx, event| {
doc_mut!(cx.editor, &doc).remove_jump_labels(view);
let alphabet = &cx.editor.config().jump_label_alphabet;
- let Some(inner ) = event.char().and_then(|ch| alphabet.iter().position(|&it| it == ch)) else {
+ let Some(inner) = event
+ .char()
+ .and_then(|ch| alphabet.iter().position(|&it| it == ch))
+ else {
return;
};
if let Some(mut range) = labels.get(outer + inner).copied() {
@@ -6073,8 +6076,8 @@ fn jump_to_label(cx: &mut Context, labels: Vec<Range>, behaviour: Movement) {
to
}
};
- Range::new(anchor, range.head)
- }else{
+ Range::new(anchor, range.head)
+ } else {
range.with_direction(Direction::Forward)
};
doc_mut!(cx.editor, &doc).set_selection(view, range.into());