mirror of https://github.com/helix-editor/helix
Fix closing buffer with custom keymap (#3633)
* Fix closing buffer with custom keymap * Add comment explaining ifpull/3678/head
parent
ec28b2b5cc
commit
45dbcb6783
|
@ -1263,6 +1263,8 @@ impl Component for EditorView {
|
||||||
if cx.editor.should_close() {
|
if cx.editor.should_close() {
|
||||||
return EventResult::Ignored(None);
|
return EventResult::Ignored(None);
|
||||||
}
|
}
|
||||||
|
// if the focused view still exists and wasn't closed
|
||||||
|
if cx.editor.tree.contains(focus) {
|
||||||
let config = cx.editor.config();
|
let config = cx.editor.config();
|
||||||
let mode = cx.editor.mode();
|
let mode = cx.editor.mode();
|
||||||
let view = cx.editor.tree.get_mut(focus);
|
let view = cx.editor.tree.get_mut(focus);
|
||||||
|
@ -1275,6 +1277,7 @@ impl Component for EditorView {
|
||||||
if mode != Mode::Insert {
|
if mode != Mode::Insert {
|
||||||
doc.append_changes_to_history(view.id);
|
doc.append_changes_to_history(view.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EventResult::Consumed(callback)
|
EventResult::Consumed(callback)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
pub fn get(&self, index: ViewId) -> &View {
|
||||||
self.try_get(index).unwrap()
|
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> {
|
pub fn try_get(&self, index: ViewId) -> Option<&View> {
|
||||||
match &self.nodes[index] {
|
match &self.nodes[index] {
|
||||||
Node {
|
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 {
|
pub fn get_mut(&mut self, index: ViewId) -> &mut View {
|
||||||
match &mut self.nodes[index] {
|
match &mut self.nodes[index] {
|
||||||
Node {
|
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 {
|
pub fn is_empty(&self) -> bool {
|
||||||
match &self.nodes[self.root] {
|
match &self.nodes[self.root] {
|
||||||
Node {
|
Node {
|
||||||
|
|
Loading…
Reference in New Issue