aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-05-17 07:36:13 +0000
committerBlaž Hrastnik2021-05-17 07:36:13 +0000
commit8f6f3290573649e3ca8cadda3541fdda45587f23 (patch)
tree33d810c0a5681e714659ba5341d07f378697dffd
parent8949347e2c5d523b7045440f1f51c42a769392dd (diff)
If switching to a previously open buffer in the same view, keep it's old offset
-rw-r--r--helix-view/src/editor.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 43311484..cf4dce28 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -81,11 +81,15 @@ impl Editor {
view.jumps.push(jump);
view.doc = id;
view.first_line = 0;
- let view_id = view.id;
+
+ let (view, doc) = self.current();
// initialize selection for view
- let doc = &mut self.documents[id];
- doc.selections.insert(view_id, Selection::point(0));
+ let selection = doc.selections.entry(view.id).or_insert(Selection::point(0));
+ // TODO: reuse align_view
+ let pos = selection.cursor();
+ let line = doc.text().char_to_line(pos);
+ view.first_line = line.saturating_sub(view.area.height as usize / 2);
return;
}