mirror of https://github.com/helix-editor/helix
Add goto_column and extend_to_column commands (#13440)
parent
1c32fb2d4d
commit
69b9db2fbb
|
@ -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 | normal: `` g\| `` |
|
||||
| `extend_to_column` | Extend to column | select: `` g\| `` |
|
||||
| `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> `` |
|
||||
|
|
|
@ -213,6 +213,7 @@ Jumps to various locations.
|
|||
| Key | Description | Command |
|
||||
| ----- | ----------- | ------- |
|
||||
| `g` | Go to line number `<n>` else start of file | `goto_file_start` |
|
||||
| <code>|</code> | Go to column number `<n>` else start of line | `goto_column` |
|
||||
| `e` | Go to the end of the file | `goto_last_line` |
|
||||
| `f` | Go to files in the selections | `goto_file` |
|
||||
| `h` | Go to the start of the line | `goto_line_start` |
|
||||
|
|
|
@ -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,28 @@ 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) {
|
||||
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) {
|
||||
let view = view_mut!(cx.editor);
|
||||
if let Some(alt) = view.docs_access_history.pop() {
|
||||
|
|
|
@ -38,6 +38,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
|
|||
"G" => goto_line,
|
||||
"g" => { "Goto"
|
||||
"g" => goto_file_start,
|
||||
"|" => goto_column,
|
||||
"e" => goto_last_line,
|
||||
"f" => goto_file,
|
||||
"h" => goto_line_start,
|
||||
|
@ -368,6 +369,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
|
|||
"v" => normal_mode,
|
||||
"g" => { "Goto"
|
||||
"g" => extend_to_file_start,
|
||||
"|" => extend_to_column,
|
||||
"e" => extend_to_last_line,
|
||||
"k" => extend_line_up,
|
||||
"j" => extend_line_down,
|
||||
|
|
Loading…
Reference in New Issue