mirror of
https://github.com/helix-editor/helix.git
synced 2025-10-06 00:13:28 +02:00
Fix bugs in Editor::focus (#14262)
This commit is contained in:
@@ -1987,28 +1987,29 @@ impl Editor {
|
||||
}
|
||||
|
||||
pub fn focus(&mut self, view_id: ViewId) {
|
||||
let prev_id = std::mem::replace(&mut self.tree.focus, view_id);
|
||||
|
||||
// if leaving the view: mode should reset and the cursor should be
|
||||
// within view
|
||||
if prev_id != view_id {
|
||||
self.enter_normal_mode();
|
||||
self.ensure_cursor_in_view(view_id);
|
||||
|
||||
// Update jumplist selections with new document changes.
|
||||
for (view, _focused) in self.tree.views_mut() {
|
||||
let doc = doc_mut!(self, &view.doc);
|
||||
view.sync_changes(doc);
|
||||
}
|
||||
let view = view!(self, view_id);
|
||||
let doc = doc_mut!(self, &view.doc);
|
||||
doc.mark_as_focused();
|
||||
let focus_lost = self.tree.get(prev_id).doc;
|
||||
dispatch(DocumentFocusLost {
|
||||
editor: self,
|
||||
doc: focus_lost,
|
||||
});
|
||||
if self.tree.focus == view_id {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset mode to normal and ensure any pending changes are committed in the old document.
|
||||
self.enter_normal_mode();
|
||||
let (view, doc) = current!(self);
|
||||
doc.append_changes_to_history(view);
|
||||
self.ensure_cursor_in_view(view_id);
|
||||
// Update jumplist selections with new document changes.
|
||||
for (view, _focused) in self.tree.views_mut() {
|
||||
let doc = doc_mut!(self, &view.doc);
|
||||
view.sync_changes(doc);
|
||||
}
|
||||
|
||||
let prev_id = std::mem::replace(&mut self.tree.focus, view_id);
|
||||
doc_mut!(self).mark_as_focused();
|
||||
|
||||
let focus_lost = self.tree.get(prev_id).doc;
|
||||
dispatch(DocumentFocusLost {
|
||||
editor: self,
|
||||
doc: focus_lost,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn focus_next(&mut self) {
|
||||
|
Reference in New Issue
Block a user