Add goto_column and extend_to_column commands (#13440)

pull/12729/head
Daniel Bowring 2025-05-02 00:12:30 +10:00 committed by GitHub
parent 1c32fb2d4d
commit 69b9db2fbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 0 deletions

View File

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

View File

@ -213,6 +213,7 @@ Jumps to various locations.
| Key | Description | Command | | Key | Description | Command |
| ----- | ----------- | ------- | | ----- | ----------- | ------- |
| `g` | Go to line number `<n>` else start of file | `goto_file_start` | | `g` | Go to line number `<n>` else start of file | `goto_file_start` |
| <code>&#124;</code> | Go to column number `<n>` else start of line | `goto_column` |
| `e` | Go to the end of the file | `goto_last_line` | | `e` | Go to the end of the file | `goto_last_line` |
| `f` | Go to files in the selections | `goto_file` | | `f` | Go to files in the selections | `goto_file` |
| `h` | Go to the start of the line | `goto_line_start` | | `h` | Go to the start of the line | `goto_line_start` |

View File

@ -451,6 +451,8 @@ impl MappableCommand {
goto_last_change, "Goto last change", goto_last_change, "Goto last change",
goto_line_start, "Goto line start", goto_line_start, "Goto line start",
goto_line_end, "Goto line end", goto_line_end, "Goto line end",
goto_column, "Goto column",
extend_to_column, "Extend to column",
goto_next_buffer, "Goto next buffer", goto_next_buffer, "Goto next buffer",
goto_previous_buffer, "Goto previous buffer", goto_previous_buffer, "Goto previous buffer",
goto_line_end_newline, "Goto newline at line end", goto_line_end_newline, "Goto newline at line end",
@ -3829,6 +3831,28 @@ fn goto_last_line_impl(cx: &mut Context, movement: Movement) {
doc.set_selection(view.id, selection); 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) {
let 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 line_end = line_end_char_index(&text, line);
let pos = graphemes::nth_next_grapheme_boundary(text, line_start, count - 1).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) { fn goto_last_accessed_file(cx: &mut Context) {
let view = view_mut!(cx.editor); let view = view_mut!(cx.editor);
if let Some(alt) = view.docs_access_history.pop() { if let Some(alt) = view.docs_access_history.pop() {

View File

@ -38,6 +38,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"G" => goto_line, "G" => goto_line,
"g" => { "Goto" "g" => { "Goto"
"g" => goto_file_start, "g" => goto_file_start,
"|" => goto_column,
"e" => goto_last_line, "e" => goto_last_line,
"f" => goto_file, "f" => goto_file,
"h" => goto_line_start, "h" => goto_line_start,
@ -368,6 +369,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"v" => normal_mode, "v" => normal_mode,
"g" => { "Goto" "g" => { "Goto"
"g" => extend_to_file_start, "g" => extend_to_file_start,
"|" => extend_to_column,
"e" => extend_to_last_line, "e" => extend_to_last_line,
"k" => extend_line_up, "k" => extend_line_up,
"j" => extend_line_down, "j" => extend_line_down,