Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Kakoune's A-S: Select first and last chars #9483

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ impl MappableCommand {
half_page_up, "Move half page up",
half_page_down, "Move half page down",
select_all, "Select whole document",
select_first_and_last_chars, "Select first and last characters of each selection",
select_regex, "Select all regex matches inside selections",
split_selection, "Split selections on regex matches",
split_selection_on_newline, "Split selection on newlines",
Expand Down Expand Up @@ -1811,6 +1812,20 @@ fn select_all(cx: &mut Context) {
doc.set_selection(view.id, Selection::single(0, end))
}

fn select_first_and_last_chars(cx: &mut Context) {
let (view, doc) = current!(cx.editor);

let selection = doc.selection(view.id).clone().transform_iter(|range| {
vec![
scdailey marked this conversation as resolved.
Show resolved Hide resolved
Range::new(range.anchor, range.anchor + 1),
Range::new(range.head - 1, range.head),
scdailey marked this conversation as resolved.
Show resolved Hide resolved
]
.into_iter()
});

doc.set_selection(view.id, selection);
}

fn select_regex(cx: &mut Context) {
let reg = cx.register.unwrap_or('/');
ui::regex_prompt(
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {


"s" => select_regex,
"A-S" => select_first_and_last_chars,
"A-s" => split_selection_on_newline,
"A-minus" => merge_selections,
"A-_" => merge_consecutive_selections,
Expand Down