on master help sign in
If switching to a previously open buffer in the same view, keep it's old offset
commit8f6f3290573649e3ca8cadda3541fdda45587f23 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 17 May 2021, 16:36 (5 years ago) parent8949347
1 file changed+7−3
helix-view/src/editor.rs+7−3
helix-view/src/editor.rs+7−3
@@ -81,11 +81,15 @@ impl Editor {
8181 view.jumps.push(jump);
8282 view.doc = id;
8383 view.first_line = 0;
84− let view_id = view.id;
84+
85+ let (view, doc) = self.current();
8586
8687 // initialize selection for view
87− let doc = &mut self.documents[id];
88− doc.selections.insert(view_id, Selection::point(0));
88+ let selection = doc.selections.entry(view.id).or_insert(Selection::point(0));
89+ // TODO: reuse align_view
90+ let pos = selection.cursor();
91+ let line = doc.text().char_to_line(pos);
92+ view.first_line = line.saturating_sub(view.area.height as usize / 2);
8993
9094 return;
9195 }