Skip to content

Commit

Permalink
Support extend for multiple goto (#909)
Browse files Browse the repository at this point in the history
gg, ge, [n]gg
  • Loading branch information
pickfire authored Oct 29, 2021
1 parent befecc8 commit 21d5355
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,25 @@ fn goto_file_start(cx: &mut Context) {
} else {
push_jump(cx.editor);
let (view, doc) = current!(cx.editor);
doc.set_selection(view.id, Selection::point(0));
let text = doc.text().slice(..);
let selection = doc
.selection(view.id)
.clone()
.transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
doc.set_selection(view.id, selection);
}
}

fn goto_file_end(cx: &mut Context) {
push_jump(cx.editor);
let (view, doc) = current!(cx.editor);
doc.set_selection(view.id, Selection::point(doc.text().len_chars()));
let text = doc.text().slice(..);
let pos = doc.text().len_chars();
let selection = doc
.selection(view.id)
.clone()
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
doc.set_selection(view.id, selection);
}

fn extend_word_impl<F>(cx: &mut Context, extend_fn: F)
Expand Down Expand Up @@ -2905,8 +2916,13 @@ fn goto_line(cx: &mut Context) {
doc.text().len_lines() - 1
};
let line_idx = std::cmp::min(count.get() - 1, max_line);
let text = doc.text().slice(..);
let pos = doc.text().line_to_char(line_idx);
doc.set_selection(view.id, Selection::point(pos));
let selection = doc
.selection(view.id)
.clone()
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
doc.set_selection(view.id, selection);
}
}

Expand All @@ -2920,8 +2936,13 @@ fn goto_last_line(cx: &mut Context) {
} else {
doc.text().len_lines() - 1
};
let text = doc.text().slice(..);
let pos = doc.text().line_to_char(line_idx);
doc.set_selection(view.id, Selection::point(pos));
let selection = doc
.selection(view.id)
.clone()
.transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
doc.set_selection(view.id, selection);
}

fn goto_last_accessed_file(cx: &mut Context) {
Expand Down

0 comments on commit 21d5355

Please sign in to comment.