Skip to content

Commit

Permalink
merge helix-editor#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 Nov 30, 2024
1 parent 3050d8d commit 28c71b1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The `insert-final-newline` option now only inserts newline if the file is not em
* [9143](https://github.com/helix-editor/helix/pull/9143) by @intarga
* [2608](https://github.com/helix-editor/helix/pull/2608) by @Philipp-M
* [11285](https://github.com/helix-editor/helix/pull/11285) by @drybalka
* [9483](https://github.com/helix-editor/helix/pull/9483) by @scdailey

### Command expansions

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 @@ -2026,6 +2027,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 28c71b1

Please sign in to comment.