diff options
author | Antoni Stevenet | 2021-06-05 00:25:46 +0000 |
---|---|---|
committer | GitHub | 2021-06-05 00:25:46 +0000 |
commit | a1f4b8f92b50fbb446400b167b344cdf189978f9 (patch) | |
tree | a5e83e878c97e51fe81ae747c86bccf0cce22be3 /helix-term/src/commands.rs | |
parent | 72eaaaac995cf55d37994c24cc0215c8370c6443 (diff) |
Add home-end keymaps, (as kakoune/vim do) (#83)
* add home-end keymaps
* implement extend methods for extend_line_start, extend_line_end
* add home-end mappings to keymaps.md
* add ^-$ extend mappings for extend mode
* pass cargo linter
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 796493ea..bc11d0fe 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -573,6 +573,37 @@ pub fn extend_line_down(cx: &mut Context) { doc.set_selection(view.id, selection); } +pub fn extend_line_end(cx: &mut Context) { + let (view, doc) = cx.current(); + + let selection = doc.selection(view.id).transform(|range| { + let text = doc.text(); + let line = text.char_to_line(range.head); + + // Line end is pos at the start of next line - 1 + // subtract another 1 because the line ends with \n + let pos = text.line_to_char(line + 1).saturating_sub(2); + Range::new(range.anchor, pos) + }); + + doc.set_selection(view.id, selection); +} + +pub fn extend_line_start(cx: &mut Context) { + let (view, doc) = cx.current(); + + let selection = doc.selection(view.id).transform(|range| { + let text = doc.text(); + let line = text.char_to_line(range.head); + + // adjust to start of the line + let pos = text.line_to_char(line); + Range::new(range.anchor, pos) + }); + + doc.set_selection(view.id, selection); +} + pub fn select_all(cx: &mut Context) { let (view, doc) = cx.current(); |