From 0890279a0e02926409ac6be07aa78e377ff203a1 Mon Sep 17 00:00:00 2001 From: Evgeniy Tatarkin Date: Thu, 7 Jul 2022 11:40:55 +0300 Subject: [PATCH] refactoring --- helix-view/src/document.rs | 5 +++++ helix-view/src/editor.rs | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index c1b2508c9ec7..9cbd2b8cbc4a 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -668,6 +668,11 @@ impl Document { } } + /// Mark document as recent used for MRU sorting + pub fn mark_as_used(&mut self) { + self.used_at = std::time::Instant::now(); + } + /// Remove a view's selection from this document. pub fn remove_view(&mut self, view_id: ViewId) { self.selections.remove(&view_id); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index ccbda28af59c..547946c7f485 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -725,6 +725,7 @@ impl Editor { let doc = self.documents.get_mut(&doc_id).unwrap(); doc.ensure_view_init(view.id); + doc.mark_as_used(); // TODO: reuse align_view let pos = doc @@ -786,7 +787,6 @@ impl Editor { view.last_modified_docs = [Some(view.doc), view.last_modified_docs[0]]; } } - doc.used_at = std::time::Instant::now(); } self.replace_document_in_view(view_id, id); @@ -797,7 +797,7 @@ impl Editor { let view_id = view!(self).id; let doc = self.documents.get_mut(&id).unwrap(); doc.ensure_view_init(view_id); - doc.used_at = std::time::Instant::now(); + doc.mark_as_used(); return; } Action::HorizontalSplit | Action::VerticalSplit => { @@ -813,7 +813,7 @@ impl Editor { // initialize selection for view let doc = self.documents.get_mut(&id).unwrap(); doc.ensure_view_init(view_id); - doc.used_at = std::time::Instant::now(); + doc.mark_as_used(); } }