mirror of https://github.com/helix-editor/helix
Add more fns to update selection ranges (#38)
* feat: add push-range & set-primary-index fns * feat: add remove-range fn --------- Co-authored-by: meepleek <ergocrab@gmail.com>pull/8675/merge^2
parent
8218db65e8
commit
46abe80bdd
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue