From 45dbcb67832e31ca5eea936628f34f5dc26c4381 Mon Sep 17 00:00:00 2001 From: A-Walrus Date: Thu, 1 Sep 2022 19:59:39 +0300 Subject: Fix closing buffer with custom keymap (#3633) * Fix closing buffer with custom keymap * Add comment explaining if--- helix-view/src/tree.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'helix-view/src') diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index eaf1dbd2..72f6af57 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -270,10 +270,18 @@ impl Tree { }) } + /// Get reference to a [`view`] by index. + /// # Panics + /// + /// Panics if `index` is not in self.nodes, or if the node's content is not [`Content::View`] . This can be checked with [`contains`] pub fn get(&self, index: ViewId) -> &View { self.try_get(index).unwrap() } + /// Try to get reference to a [`view`] by index. Returns `None` if node content is not a [`Content::View`] + /// # Panics + /// + /// Panics if `index` is not in self.nodes. This can be checked with [`Self::contains`] pub fn try_get(&self, index: ViewId) -> Option<&View> { match &self.nodes[index] { Node { @@ -284,6 +292,10 @@ impl Tree { } } + /// Get a mutable reference to a [`view`] by index. + /// # Panics + /// + /// Panics if `index` is not in self.nodes, or if the node's content is not [`Content::View`] . This can be checked with [`Self::contains`] pub fn get_mut(&mut self, index: ViewId) -> &mut View { match &mut self.nodes[index] { Node { @@ -294,6 +306,11 @@ impl Tree { } } + /// Check if tree contains a [`Node`] with a given index. + pub fn contains(&self, index: ViewId) -> bool { + self.nodes.contains_key(index) + } + pub fn is_empty(&self) -> bool { match &self.nodes[self.root] { Node { -- cgit v1.2.3-70-g09d2