on master help sign in
Store intra-files jumps (goto) on the jumplist.
commit742b3a709fd7680d77bcda5ae08f2a9539b6a20e authorBlaž Hrastnik <blaz@mxxn.io> dateMon 29 Mar 2021, 16:32 (6 years ago) parent0083a6c
6 files changed+30−5
helix-core/src/selection.rs+1−1 helix-term/src/commands.rs+16 helix-term/src/keymap.rs+1 helix-term/src/ui/mod.rs+1−1 helix-view/src/document.rs+5 helix-view/src/view.rs+6−3
helix-core/src/selection.rs+1−1
@@ -127,7 +127,7 @@ impl Range {
127127
128128/// A selection consists of one or more selection ranges.
129129/// invariant: A selection can never be empty (always contains at least primary range).
130−#[derive(Debug, Clone)]
130+#[derive(Debug, Clone, PartialEq, Eq)]
131131pub struct Selection {
132132 ranges: SmallVec<[Range; 1]>,
133133 primary_index: usize,
helix-term/src/commands.rs+16
@@ -238,11 +238,13 @@ pub fn move_next_word_end(cx: &mut Context) {
238238}
239239
240240pub fn move_file_start(cx: &mut Context) {
241+ push_jump(cx);
241242 let doc = cx.doc();
242243 doc.set_selection(Selection::point(0));
243244}
244245
245246pub fn move_file_end(cx: &mut Context) {
247+ push_jump(cx);
246248 let doc = cx.doc();
247249 let text = doc.text();
248250 let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
@@ -1027,9 +1029,21 @@ pub fn normal_mode(cx: &mut Context) {
10271029 }
10281030}
10291031
1032+// Store a jump on the jumplist.
1033+fn push_jump(cx: &mut Context) {
1034+ let jump = {
1035+ let doc = cx.doc();
1036+ (doc.id(), doc.selection().clone())
1037+ };
1038+ cx.view().jumps.push(jump);
1039+}
1040+
10301041pub fn goto_mode(cx: &mut Context) {
10311042 let count = cx.count;
1043+
10321044 if count > 1 {
1045+ push_jump(cx);
1046+
10331047 // TODO: can't go to line 1 since we can't distinguish between g and 1g, g gets converted
10341048 // to 1g
10351049 let doc = cx.doc();
@@ -1069,6 +1083,8 @@ pub fn exit_select_mode(cx: &mut Context) {
10691083fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
10701084 use helix_view::editor::Action;
10711085
1086+ push_jump(cx);
1087+
10721088 fn jump_to(editor: &mut Editor, location: &lsp::Location, action: Action) {
10731089 let id = editor
10741090 .open(PathBuf::from(location.uri.path()), action)
helix-term/src/keymap.rs+1
@@ -258,6 +258,7 @@ pub fn default() -> Keymaps {
258258
259259 ctrl!('i') => commands::jump_forward, // TODO: ctrl-i conflicts tab
260260 ctrl!('o') => commands::jump_backward,
261+ // ctrl!('s') => commands::save_selection,
261262 );
262263 // TODO: decide whether we want normal mode to also be select mode (kakoune-like), or whether
263264 // we keep this separate select mode. More keys can fit into normal mode then, but it's weird
helix-term/src/ui/mod.rs+1−1
@@ -49,7 +49,7 @@ pub fn regex_prompt(
4949 doc.set_selection(snapshot.clone());
5050 }
5151 PromptEvent::Validate => {
52− //
52+ // TODO: push_jump to store selection just before jump
5353 }
5454 PromptEvent::Update => {
5555 // skip empty input, TODO: trigger default
helix-view/src/document.rs+5
@@ -274,6 +274,11 @@ impl Document {
274274 self.history.commit_revision(&transaction, &old_state);
275275 }
276276
277+ #[inline]
278+ pub fn id(&self) -> DocumentId {
279+ self.id
280+ }
281+
277282 #[inline]
278283 pub fn mode(&self) -> Mode {
279284 self.mode
helix-view/src/view.rs+6−3
@@ -27,9 +27,12 @@ impl JumpList {
2727 }
2828
2929 pub fn push(&mut self, jump: Jump) {
30− self.jumps.truncate(self.current + 1);
31− self.jumps.push(jump);
32− self.current += 1;
30+ self.jumps.truncate(self.current);
31+ // don't push duplicates
32+ if self.jumps.last() != Some(&jump) {
33+ self.jumps.push(jump);
34+ self.current = self.jumps.len();
35+ }
3336 }
3437
3538 pub fn forward(&mut self, count: usize) -> Option<&Jump> {