mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 01:16:18 +04:00
Fix closing buffer with custom keymap (#3633)
* Fix closing buffer with custom keymap * Add comment explaining if
This commit is contained in:
parent
ec28b2b5cc
commit
45dbcb6783
@ -1263,17 +1263,20 @@ fn handle_event(
|
||||
if cx.editor.should_close() {
|
||||
return EventResult::Ignored(None);
|
||||
}
|
||||
let config = cx.editor.config();
|
||||
let mode = cx.editor.mode();
|
||||
let view = cx.editor.tree.get_mut(focus);
|
||||
let doc = cx.editor.documents.get_mut(&view.doc).unwrap();
|
||||
// if the focused view still exists and wasn't closed
|
||||
if cx.editor.tree.contains(focus) {
|
||||
let config = cx.editor.config();
|
||||
let mode = cx.editor.mode();
|
||||
let view = cx.editor.tree.get_mut(focus);
|
||||
let doc = cx.editor.documents.get_mut(&view.doc).unwrap();
|
||||
|
||||
view.ensure_cursor_in_view(doc, config.scrolloff);
|
||||
view.ensure_cursor_in_view(doc, config.scrolloff);
|
||||
|
||||
// Store a history state if not in insert mode. This also takes care of
|
||||
// committing changes when leaving insert mode.
|
||||
if mode != Mode::Insert {
|
||||
doc.append_changes_to_history(view.id);
|
||||
// Store a history state if not in insert mode. This also takes care of
|
||||
// committing changes when leaving insert mode.
|
||||
if mode != Mode::Insert {
|
||||
doc.append_changes_to_history(view.id);
|
||||
}
|
||||
}
|
||||
|
||||
EventResult::Consumed(callback)
|
||||
|
@ -270,10 +270,18 @@ pub fn views_mut(&mut self) -> impl Iterator<Item = (&mut View, bool)> {
|
||||
})
|
||||
}
|
||||
|
||||
/// 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 @@ pub fn try_get(&self, index: ViewId) -> Option<&View> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 @@ pub fn get_mut(&mut self, index: ViewId) -> &mut View {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user