diff options
author | Kangwook Lee (이강욱) | 2021-09-07 14:22:39 +0000 |
---|---|---|
committer | GitHub | 2021-09-07 14:22:39 +0000 |
commit | 7a9db951829d37447a414f03802297f4b43e02a6 (patch) | |
tree | a022e8c4a672d268a6a265a2b089b2c2d8526fb5 /helix-term/src/commands.rs | |
parent | fd36fbdebfa6508699979dc426725cbbc2dbe295 (diff) |
Add command to extend to line start or end (#717)
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r-- | helix-term/src/commands.rs | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 2fbed6b3..38e65537 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -252,6 +252,9 @@ impl Command { // TODO: different description ? goto_line_end_newline, "Goto line end", goto_first_nonwhitespace, "Goto first non-blank in line", + extend_to_line_start, "Extend to line start", + extend_to_line_end, "Extend to line end", + extend_to_line_end_newline, "Extend to line end", signature_help, "Show signature help", insert_tab, "Insert tab char", insert_newline, "Insert newline char", @@ -407,7 +410,7 @@ fn extend_line_down(cx: &mut Context) { move_impl(cx, move_vertically, Direction::Forward, Movement::Extend) } -fn goto_line_end(cx: &mut Context) { +fn goto_line_end_impl(cx: &mut Context, movement: Movement) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -418,12 +421,20 @@ fn goto_line_end(cx: &mut Context) { let pos = graphemes::prev_grapheme_boundary(text, line_end_char_index(&text, line)) .max(line_start); - range.put_cursor(text, pos, doc.mode == Mode::Select) + range.put_cursor(text, pos, movement == Movement::Extend) }); doc.set_selection(view.id, selection); } -fn goto_line_end_newline(cx: &mut Context) { +fn goto_line_end(cx: &mut Context) { + goto_line_end_impl(cx, Movement::Move) +} + +fn extend_to_line_end(cx: &mut Context) { + goto_line_end_impl(cx, Movement::Extend) +} + +fn goto_line_end_newline_impl(cx: &mut Context, movement: Movement) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -431,12 +442,20 @@ fn goto_line_end_newline(cx: &mut Context) { let line = range.cursor_line(text); let pos = line_end_char_index(&text, line); - range.put_cursor(text, pos, doc.mode == Mode::Select) + range.put_cursor(text, pos, movement == Movement::Extend) }); doc.set_selection(view.id, selection); } -fn goto_line_start(cx: &mut Context) { +fn goto_line_end_newline(cx: &mut Context) { + goto_line_end_newline_impl(cx, Movement::Move) +} + +fn extend_to_line_end_newline(cx: &mut Context) { + goto_line_end_newline_impl(cx, Movement::Extend) +} + +fn goto_line_start_impl(cx: &mut Context, movement: Movement) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -445,11 +464,19 @@ fn goto_line_start(cx: &mut Context) { // adjust to start of the line let pos = text.line_to_char(line); - range.put_cursor(text, pos, doc.mode == Mode::Select) + range.put_cursor(text, pos, movement == Movement::Extend) }); doc.set_selection(view.id, selection); } +fn goto_line_start(cx: &mut Context) { + goto_line_start_impl(cx, Movement::Move) +} + +fn extend_to_line_start(cx: &mut Context) { + goto_line_start_impl(cx, Movement::Extend) +} + fn goto_first_nonwhitespace(cx: &mut Context) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); |