on master help sign in
If switching to a previously open buffer in the same view, keep it's old offset
8f6f329Blaž Hrastnik
helix-view/src/editor.rs+7−3
@@ -81,11 +81,15 @@ impl Editor {
81 view.jumps.push(jump);
81 view.jumps.push(jump);
82 view.doc = id;
82 view.doc = id;
83 view.first_line = 0;
83 view.first_line = 0;
84− let view_id = view.id;
84+
85+ let (view, doc) = self.current();
85
86
86 // initialize selection for view
87 // initialize selection for view
87− let doc = &mut self.documents[id];
88+ let selection = doc.selections.entry(view.id).or_insert(Selection::point(0));
88− doc.selections.insert(view_id, 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);
89
93
90 return;
94 return;
91 }
95 }