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 all 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
1 change: 1 addition & 0 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Normal mode is the default mode when you launch helix. You can return to it from
| `s` | Select all regex matches inside selections | `select_regex` |
| `S` | Split selection into sub selections on regex matches | `split_selection` |
| `Alt-s` | Split selection on newlines | `split_selection_on_newline` |
| `Alt-S` | Select first and last characters of each selection | `select_first_and_last_chars` |
| `Alt-minus` | Merge selections | `merge_selections` |
| `Alt-_` | Merge consecutive selections | `merge_consecutive_selections` |
| `&` | Align selection in columns | `align_selections` |
Expand Down
16 changes: 16 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,21 @@ 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 text = doc.text().slice(..);

let selection = doc.selection(view.id).clone().transform_iter(|range| {
[
Range::point(range.from()),
Range::point(graphemes::prev_grapheme_boundary(text, range.to())),
]
.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