Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-view/src/editor.rs')
| -rw-r--r-- | helix-view/src/editor.rs | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 34854054..cd8560e0 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -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); + if self.tree.focus == view_id { + return; + } - // 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); + // 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); - doc.mark_as_focused(); - let focus_lost = self.tree.get(prev_id).doc; - dispatch(DocumentFocusLost { - editor: self, - doc: focus_lost, - }); + 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) { |