aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/view.rs
diff options
context:
space:
mode:
authorMatouš Dzivjak2022-04-27 16:14:46 +0000
committerGitHub2022-04-27 16:14:46 +0000
commit52f5a4228aef2d31cf20aeee2bed317ba1767c18 (patch)
treeec3fa81c5749ad512bfa64f2ae1f3770e6fe03d9 /helix-view/src/view.rs
parenta3c0b4db48bb286a9b59a3fb1089607f6f29388c (diff)
feat(commands): better handling of buffer-close (#1397)
* feat(commands): better handling of buffer-close Previously, when closing buffer, you would loose cursor position in other docs. Also, all splits where the buffer was open would be closed. This PR changes the behavior, if the view has also other buffer previously viewed it switches back to the last one instead of the view being closed. As a side effect, since the views are persisted, the cursor history is persisted as well. Fixes: https://github.com/helix-editor/helix/issues/1186 * Adjust buffer close behavior * Remove closed documents from jump history * Fix after rebase
Diffstat (limited to 'helix-view/src/view.rs')
-rw-r--r--helix-view/src/view.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index 7cf88c2e..3450da9b 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -72,8 +72,8 @@ pub struct View {
pub area: Rect,
pub doc: DocumentId,
pub jumps: JumpList,
- /// the last accessed file before the current one
- pub last_accessed_doc: Option<DocumentId>,
+ // documents accessed from this view from the oldest one to last viewed one
+ pub docs_access_history: Vec<DocumentId>,
/// the last modified files before the current one
/// ordered from most frequent to least frequent
// uses two docs because we want to be able to swap between the
@@ -110,13 +110,20 @@ impl View {
offset: Position::new(0, 0),
area: Rect::default(), // will get calculated upon inserting into tree
jumps: JumpList::new((doc, Selection::point(0))), // TODO: use actual sel
- last_accessed_doc: None,
+ docs_access_history: Vec::new(),
last_modified_docs: [None, None],
object_selections: Vec::new(),
gutters,
}
}
+ pub fn add_to_history(&mut self, id: DocumentId) {
+ if let Some(pos) = self.docs_access_history.iter().position(|&doc| doc == id) {
+ self.docs_access_history.remove(pos);
+ }
+ self.docs_access_history.push(id);
+ }
+
pub fn inner_area(&self) -> Rect {
// TODO: cache this
let offset = self