aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-02-19 08:46:43 +0000
committerBlaž Hrastnik2021-02-19 08:46:43 +0000
commit7877647cf0812380623b0087fbd7bea0ee9fae20 (patch)
treea386d8b5534310763dbab12b9e21ac893b431f94 /helix-view/src/editor.rs
parent1e1dae1c11bf00b56213995679647ff30b664a17 (diff)
Allow closing individual views.
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 762b9e96..52285bf8 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -4,12 +4,13 @@ use crate::{Document, View};
use std::path::PathBuf;
+use slotmap::DefaultKey as Key;
+
use anyhow::Error;
pub struct Editor {
pub tree: Tree,
// pub documents: Vec<Document>,
- pub should_close: bool,
pub count: Option<usize>,
pub theme: Theme, // TODO: share one instance
pub language_servers: helix_lsp::Registry,
@@ -25,7 +26,6 @@ impl Editor {
Self {
tree: Tree::new(area),
- should_close: false,
count: None,
theme,
language_servers,
@@ -54,10 +54,19 @@ impl Editor {
}
let view = View::new(doc)?;
- self.tree.insert(view);
+ let id = self.tree.insert(view);
+ self.tree.get_mut(id).id = id;
Ok(())
}
+ pub fn close(&mut self, id: Key) {
+ self.tree.remove(id)
+ }
+
+ pub fn should_close(&mut self) -> bool {
+ self.tree.is_empty()
+ }
+
pub fn view(&self) -> &View {
self.tree.get(self.tree.focus)
}