Skip to content

Commit

Permalink
merge 9483 by scdailey
Browse files Browse the repository at this point in the history
Added kakoune's A-S command

Small formatting change

Updated to use grapheme helpers

Change to Range::point and fix keymap formatting
  • Loading branch information
Axlefublr committed Dec 10, 2024
1 parent a9858d8 commit f8fdd11
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/static-cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
| `page_cursor_half_up` | Move page and cursor half up | normal: `` <C-u> ``, `` Z<C-u> ``, `` z<C-u> ``, `` Z<backspace> ``, `` z<backspace> ``, select: `` <C-u> ``, `` Z<C-u> ``, `` z<C-u> ``, `` Z<backspace> ``, `` z<backspace> `` |
| `page_cursor_half_down` | Move page and cursor half down | normal: `` <C-d> ``, `` Z<C-d> ``, `` z<C-d> ``, `` Z<space> ``, `` z<space> ``, select: `` <C-d> ``, `` Z<C-d> ``, `` z<C-d> ``, `` Z<space> ``, `` z<space> `` |
| `select_all` | Select whole document | normal: `` % ``, select: `` % `` |
| `select_first_and_last_chars` | Select first and last characters of each selection | normal: `` <A-S> ``, select: `` <A-S> `` |
| `select_regex` | Select all regex matches inside selections | normal: `` s ``, select: `` s `` |
| `split_selection` | Split selections on regex matches | normal: `` S ``, select: `` S `` |
| `split_selection_on_newline` | Split selection on newlines | normal: `` <A-s> ``, select: `` <A-s> `` |
Expand Down
1 change: 1 addition & 0 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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 @@ -349,6 +349,7 @@ impl MappableCommand {
page_cursor_half_up, "Move page and cursor half up",
page_cursor_half_down, "Move page and cursor half 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 @@ -2004,6 +2005,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 @@ -79,6 +79,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

0 comments on commit f8fdd11

Please sign in to comment.