Add goto_column and extend_to_column commands

pull/13440/head
Daniel Bowring 2025-04-29 16:50:25 +10:00
parent b42e1d20d2
commit d306c85f60
No known key found for this signature in database
2 changed files with 28 additions and 0 deletions

View File

@ -153,6 +153,8 @@
| `goto_last_change` | Goto last change | normal: `` ]G ``, select: `` ]G `` |
| `goto_line_start` | Goto line start | normal: `` gh ``, `` <home> ``, select: `` gh ``, insert: `` <home> `` |
| `goto_line_end` | Goto line end | normal: `` gl ``, `` <end> ``, select: `` gl `` |
| `goto_column` | Goto column | |
| `extend_to_column` | Extend to column | |
| `goto_next_buffer` | Goto next buffer | normal: `` gn ``, select: `` gn `` |
| `goto_previous_buffer` | Goto previous buffer | normal: `` gp ``, select: `` gp `` |
| `goto_line_end_newline` | Goto newline at line end | insert: `` <end> `` |

View File

@ -451,6 +451,8 @@ impl MappableCommand {
goto_last_change, "Goto last change",
goto_line_start, "Goto line start",
goto_line_end, "Goto line end",
goto_column, "Goto column",
extend_to_column, "Extend to column",
goto_next_buffer, "Goto next buffer",
goto_previous_buffer, "Goto previous buffer",
goto_line_end_newline, "Goto newline at line end",
@ -3829,6 +3831,30 @@ fn goto_last_line_impl(cx: &mut Context, movement: Movement) {
doc.set_selection(view.id, selection);
}
fn goto_column(cx: &mut Context) {
goto_column_impl(cx, Movement::Move);
}
fn extend_to_column(cx: &mut Context) {
goto_column_impl(cx, Movement::Extend);
}
fn goto_column_impl(cx: &mut Context, movement: Movement) {
if let Some(count) = cx.count {
let (view, doc) = current!(cx.editor);
let text = doc.text().slice(..);
let selection = doc.selection(view.id).clone().transform(|range| {
let line = range.cursor_line(text);
let line_start = text.line_to_char(line);
let target = line_start + count.get();
let line_end = line_end_char_index(&text, line);
let pos = graphemes::prev_grapheme_boundary(text, target).min(line_end);
range.put_cursor(text, pos, movement == Movement::Extend)
});
doc.set_selection(view.id, selection);
}
}
fn goto_last_accessed_file(cx: &mut Context) {
let view = view_mut!(cx.editor);
if let Some(alt) = view.docs_access_history.pop() {