@@ -667,7 +667,7 @@ impl Editor {
667 view.jumps.push(jump);
667 view.jumps.push(jump);
668 // Set last accessed doc if it is a different document
668 // Set last accessed doc if it is a different document
669 if doc.id != id {
669 if doc.id != id {
670− view.last_accessed_doc = Some(view.doc);
670+ view.add_to_history(view.doc);
671 // Set last modified doc if modified and last modified doc is different
671 // Set last modified doc if modified and last modified doc is different
672 if std::mem::take(&mut doc.modified_since_accessed)
672 if std::mem::take(&mut doc.modified_since_accessed)
673 && view.last_modified_docs[0] != Some(view.doc)
673 && view.last_modified_docs[0] != Some(view.doc)
@@ -785,20 +785,41 @@ impl Editor {
785 tokio::spawn(language_server.text_document_did_close(doc.identifier()));
785 tokio::spawn(language_server.text_document_did_close(doc.identifier()));
788− let views_to_close = self
788+ enum Action {
790+ ReplaceDoc(ViewId, DocumentId),
793+ let actions: Vec<Action> = self
790− .views()
795+ .views_mut()
791 .filter_map(|(view, _focus)| {
796 .filter_map(|(view, _focus)| {
797+ // remove the document from jump list of all views
798+ view.jumps.remove(&doc_id);
792 if view.doc == doc_id {
800 if view.doc == doc_id {
793− Some(view.id)
801+ // something was previously open in the view, switch to previous doc
802+ if let Some(prev_doc) = view.docs_access_history.pop() {
803+ Some(Action::ReplaceDoc(view.id, prev_doc))
805+ // only the document that is being closed was in the view, close it
806+ Some(Action::Close(view.id))
798− .collect::<Vec<_>>();
812+ .collect();
800− for view_id in views_to_close {
814+ for action in actions {
816+ Action::Close(view_id) => {
801− self.close(view_id);
817+ self.close(view_id);
819+ Action::ReplaceDoc(view_id, doc_id) => {
820+ self.replace_document_in_view(view_id, doc_id);
804 self.documents.remove(&doc_id);
825 self.documents.remove(&doc_id);