on master help sign in
Store intra-files jumps (goto) on the jumplist.
742b3a7Blaž Hrastnik
helix-core/src/selection.rs+1−1
@@ -127,7 +127,7 @@ impl Range {
127
127
128/// A selection consists of one or more selection ranges.
128/// A selection consists of one or more selection ranges.
129/// invariant: A selection can never be empty (always contains at least primary range).
129/// invariant: A selection can never be empty (always contains at least primary range).
130−#[derive(Debug, Clone)]
130+#[derive(Debug, Clone, PartialEq, Eq)]
131pub struct Selection {
131pub struct Selection {
132 ranges: SmallVec<[Range; 1]>,
132 ranges: SmallVec<[Range; 1]>,
133 primary_index: usize,
133 primary_index: usize,
helix-term/src/commands.rs+16
@@ -238,11 +238,13 @@ pub fn move_next_word_end(cx: &mut Context) {
238}
238}
239
239
240pub fn move_file_start(cx: &mut Context) {
240pub fn move_file_start(cx: &mut Context) {
241+ push_jump(cx);
241 let doc = cx.doc();
242 let doc = cx.doc();
242 doc.set_selection(Selection::point(0));
243 doc.set_selection(Selection::point(0));
243}
244}
244
245
245pub fn move_file_end(cx: &mut Context) {
246pub fn move_file_end(cx: &mut Context) {
247+ push_jump(cx);
246 let doc = cx.doc();
248 let doc = cx.doc();
247 let text = doc.text();
249 let text = doc.text();
248 let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
250 let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
@@ -1027,9 +1029,21 @@ pub fn normal_mode(cx: &mut Context) {
1027 }
1029 }
1028}
1030}
1029
1031
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+
1030pub fn goto_mode(cx: &mut Context) {
1041pub fn goto_mode(cx: &mut Context) {
1031 let count = cx.count;
1042 let count = cx.count;
1043+
1032 if count > 1 {
1044 if count > 1 {
1045+ push_jump(cx);
1046+
1033 // TODO: can't go to line 1 since we can't distinguish between g and 1g, g gets converted
1047 // TODO: can't go to line 1 since we can't distinguish between g and 1g, g gets converted
1034 // to 1g
1048 // to 1g
1035 let doc = cx.doc();
1049 let doc = cx.doc();
@@ -1069,6 +1083,8 @@ pub fn exit_select_mode(cx: &mut Context) {
1069fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1083fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1070 use helix_view::editor::Action;
1084 use helix_view::editor::Action;
1071
1085
1086+ push_jump(cx);
1087+
1072 fn jump_to(editor: &mut Editor, location: &lsp::Location, action: Action) {
1088 fn jump_to(editor: &mut Editor, location: &lsp::Location, action: Action) {
1073 let id = editor
1089 let id = editor
1074 .open(PathBuf::from(location.uri.path()), action)
1090 .open(PathBuf::from(location.uri.path()), action)
helix-term/src/keymap.rs+1
@@ -258,6 +258,7 @@ pub fn default() -> Keymaps {
258
258
259 ctrl!('i') => commands::jump_forward, // TODO: ctrl-i conflicts tab
259 ctrl!('i') => commands::jump_forward, // TODO: ctrl-i conflicts tab
260 ctrl!('o') => commands::jump_backward,
260 ctrl!('o') => commands::jump_backward,
261+ // ctrl!('s') => commands::save_selection,
261 );
262 );
262 // TODO: decide whether we want normal mode to also be select mode (kakoune-like), or whether
263 // TODO: decide whether we want normal mode to also be select mode (kakoune-like), or whether
263 // we keep this separate select mode. More keys can fit into normal mode then, but it's weird
264 // 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(
49 doc.set_selection(snapshot.clone());
49 doc.set_selection(snapshot.clone());
50 }
50 }
51 PromptEvent::Validate => {
51 PromptEvent::Validate => {
52− //
52+ // TODO: push_jump to store selection just before jump
53 }
53 }
54 PromptEvent::Update => {
54 PromptEvent::Update => {
55 // skip empty input, TODO: trigger default
55 // skip empty input, TODO: trigger default
helix-view/src/document.rs+5
@@ -274,6 +274,11 @@ impl Document {
274 self.history.commit_revision(&transaction, &old_state);
274 self.history.commit_revision(&transaction, &old_state);
275 }
275 }
276
276
277+ #[inline]
278+ pub fn id(&self) -> DocumentId {
279+ self.id
280+ }
281+
277 #[inline]
282 #[inline]
278 pub fn mode(&self) -> Mode {
283 pub fn mode(&self) -> Mode {
279 self.mode
284 self.mode
helix-view/src/view.rs+6−3
@@ -27,9 +27,12 @@ impl JumpList {
27 }
27 }
28
28
29 pub fn push(&mut self, jump: Jump) {
29 pub fn push(&mut self, jump: Jump) {
30− self.jumps.truncate(self.current + 1);
30+ self.jumps.truncate(self.current);
31+ // don't push duplicates
32+ if self.jumps.last() != Some(&jump) {
31− self.jumps.push(jump);
33+ self.jumps.push(jump);
32− self.current += 1;
34+ self.current = self.jumps.len();
35+ }
33 }
36 }
34
37
35 pub fn forward(&mut self, count: usize) -> Option<&Jump> {
38 pub fn forward(&mut self, count: usize) -> Option<&Jump> {