aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-28 21:11:08 +0000
committerNathan Vegdahl2021-07-28 21:11:08 +0000
commita873e719d5dd1816434c16bb02d74f1e00ca847a (patch)
tree7ea6f6a37f5a7f9e12f3fab4c7e07cb21ae0ec0b /helix-term/src/commands.rs
parentaead4e69a66ba004aa34e5a1a59e05239117250e (diff)
parentb90450b9e8b995e96a723a5d8c7b179ad2967c5a (diff)
Merge branch 'master' into great_line_ending_and_cursor_range_cleanup
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs24
1 files changed, 20 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index a37d2d26..acf1c454 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -228,13 +228,14 @@ impl Command {
goto_definition, "Goto definition",
goto_type_definition, "Goto type definition",
goto_implementation, "Goto implementation",
- goto_file_start, "Goto file start",
+ goto_file_start, "Goto file start/line",
goto_file_end, "Goto file end",
goto_reference, "Goto references",
goto_window_top, "Goto window top",
goto_window_middle, "Goto window middle",
goto_window_bottom, "Goto window bottom",
goto_last_accessed_file, "Goto last accessed file",
+ goto_line, "Goto line",
goto_first_diag, "Goto first diagnostic",
goto_last_diag, "Goto last diagnostic",
goto_next_diag, "Goto next diagnostic",
@@ -553,9 +554,13 @@ fn move_next_long_word_end(cx: &mut Context) {
}
fn goto_file_start(cx: &mut Context) {
- push_jump(cx.editor);
- let (view, doc) = current!(cx.editor);
- doc.set_selection(view.id, Selection::point(0));
+ if cx.count.is_some() {
+ goto_line(cx);
+ } else {
+ push_jump(cx.editor);
+ let (view, doc) = current!(cx.editor);
+ doc.set_selection(view.id, Selection::point(0));
+ }
}
fn goto_file_end(cx: &mut Context) {
@@ -2442,6 +2447,17 @@ fn push_jump(editor: &mut Editor) {
view.jumps.push(jump);
}
+fn goto_line(cx: &mut Context) {
+ if let Some(count) = cx.count {
+ push_jump(cx.editor);
+
+ let (view, doc) = current!(cx.editor);
+ let line_idx = std::cmp::min(count.get() - 1, doc.text().len_lines().saturating_sub(2));
+ let pos = doc.text().line_to_char(line_idx);
+ doc.set_selection(view.id, Selection::point(pos));
+ }
+}
+
fn goto_last_accessed_file(cx: &mut Context) {
let alternate_file = view!(cx.editor).last_accessed_doc;
if let Some(alt) = alternate_file {