Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 2669d8dd..86d58627 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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() {