From 8f6f3290573649e3ca8cadda3541fdda45587f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 17 May 2021 16:36:13 +0900 Subject: [PATCH] If switching to a previously open buffer in the same view, keep it's old offset --- helix-view/src/editor.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 433114844..cf4dce288 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; }