aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/editor.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/editor.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/editor.rs')
-rw-r--r--helix-view/src/editor.rs35
1 files changed, 28 insertions, 7 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 79775c89..38826f4b 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -667,7 +667,7 @@ impl Editor {
view.jumps.push(jump);
// Set last accessed doc if it is a different document
if doc.id != id {
- view.last_accessed_doc = Some(view.doc);
+ view.add_to_history(view.doc);
// Set last modified doc if modified and last modified doc is different
if std::mem::take(&mut doc.modified_since_accessed)
&& view.last_modified_docs[0] != Some(view.doc)
@@ -785,20 +785,41 @@ impl Editor {
tokio::spawn(language_server.text_document_did_close(doc.identifier()));
}
- let views_to_close = self
+ enum Action {
+ Close(ViewId),
+ ReplaceDoc(ViewId, DocumentId),
+ }
+
+ let actions: Vec<Action> = self
.tree
- .views()
+ .views_mut()
.filter_map(|(view, _focus)| {
+ // remove the document from jump list of all views
+ view.jumps.remove(&doc_id);
+
if view.doc == doc_id {
- Some(view.id)
+ // something was previously open in the view, switch to previous doc
+ if let Some(prev_doc) = view.docs_access_history.pop() {
+ Some(Action::ReplaceDoc(view.id, prev_doc))
+ } else {
+ // only the document that is being closed was in the view, close it
+ Some(Action::Close(view.id))
+ }
} else {
None
}
})
- .collect::<Vec<_>>();
+ .collect();
- for view_id in views_to_close {
- self.close(view_id);
+ for action in actions {
+ match action {
+ Action::Close(view_id) => {
+ self.close(view_id);
+ }
+ Action::ReplaceDoc(view_id, doc_id) => {
+ self.replace_document_in_view(view_id, doc_id);
+ }
+ }
}
self.documents.remove(&doc_id);