diff --git a/helix-term/src/commands/engine/steel.rs b/helix-term/src/commands/engine/steel.rs index 91c27a3f5..8d7b61c15 100644 --- a/helix-term/src/commands/engine/steel.rs +++ b/helix-term/src/commands/engine/steel.rs @@ -384,6 +384,21 @@ fn load_static_commands(engine: &mut Engine, generate_sources: bool) { set_selection, "Update the selection object to the current selection within the editor" ); + function1!( + "push-range-to-selection!", + push_range_to_selection, + "Push a new range to a selection. The new selection will be the primary one" + ); + function1!( + "set-current-selection-primary-index!", + set_selection_primary_index, + "Set the primary index of the current selection" + ); + function1!( + "remove-current-selection-range!", + remove_selection_range, + "Remove a range from the current selection" + ); function1!( "regex-selection", @@ -4429,6 +4444,25 @@ fn set_selection(cx: &mut Context, selection: Selection) { doc.set_selection(view.id, selection) } +fn push_range_to_selection(cx: &mut Context, range: Range) { + let (view, doc) = current!(cx.editor); + let selection = doc.selection(view.id).clone(); + doc.set_selection(view.id, selection.push(range)) +} + +fn set_selection_primary_index(cx: &mut Context, primary_index: usize) { + let (view, doc) = current!(cx.editor); + let mut selection = doc.selection(view.id).clone(); + selection.set_primary_index(primary_index); + doc.set_selection(view.id, selection) +} + +fn remove_selection_range(cx: &mut Context, index: usize) { + let (view, doc) = current!(cx.editor); + let selection = doc.selection(view.id).clone(); + doc.set_selection(view.id, selection.remove(index)) +} + fn current_line_number(cx: &mut Context) -> usize { let (view, doc) = current_ref!(cx.editor); helix_core::coords_at_pos(