From 8e41e19890b9f9102fda6c025ca627fa0e1a7fe5 Mon Sep 17 00:00:00 2001 From: emilylime Date: Tue, 24 Sep 2024 09:56:43 +0300 Subject: [PATCH] Switch document list to use indexmap::IndexMap (added dependency) --- Cargo.lock | 1 + helix-view/Cargo.toml | 1 + helix-view/src/editor.rs | 9 +++++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7156fc27e..686390783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1433,6 +1433,7 @@ dependencies = [ "helix-stdx", "helix-tui", "helix-vcs", + "indexmap", "libc", "log", "once_cell", diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index ddfa9f7e4..fa06c9221 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -51,6 +51,7 @@ log = "~0.4" parking_lot = "0.12.3" thiserror.workspace = true +indexmap = "2.5.0" [target.'cfg(windows)'.dependencies] clipboard-win = { version = "5.4", features = ["std"] } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 26dea3a21..3135e1ef4 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -18,6 +18,7 @@ use helix_vcs::DiffProviderRegistry; use futures_util::stream::select_all::SelectAll; use futures_util::{future, StreamExt}; use helix_lsp::{Call, LanguageServerId}; +use indexmap::IndexMap; use tokio_stream::wrappers::UnboundedReceiverStream; use std::{ @@ -1015,7 +1016,7 @@ pub struct Editor { pub mode: Mode, pub tree: Tree, pub next_document_id: DocumentId, - pub documents: BTreeMap, + pub documents: IndexMap, // We Flatten<> to resolve the inner DocumentSavedEventFuture. For that we need a stream of streams, hence the Once<>. // https://stackoverflow.com/a/66875668 @@ -1164,7 +1165,7 @@ impl Editor { mode: Mode::Normal, tree: Tree::new(area), next_document_id: DocumentId::default(), - documents: BTreeMap::new(), + documents: IndexMap::new(), saves: HashMap::new(), save_queue: SelectAll::new(), write_count: 0, @@ -1595,7 +1596,7 @@ impl Editor { // Copy `doc.id` into a variable before calling `self.documents.remove`, which requires a mutable // borrow, invalidating direct access to `doc.id`. let id = doc.id; - self.documents.remove(&id); + self.documents.shift_remove(&id); // Remove the scratch buffer from any jumplists for (view, _) in self.tree.views_mut() { @@ -1796,7 +1797,7 @@ impl Editor { } } - self.documents.remove(&doc_id); + self.documents.shift_remove(&doc_id); // If the document we removed was visible in all views, we will have no more views. We don't // want to close the editor just for a simple buffer close, so we need to create a new view