Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--helix-term/src/ui/editor.rs3
-rw-r--r--helix-view/src/editor.rs39
2 files changed, 22 insertions, 20 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index 1f0ff4b3..d268edfa 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -1159,6 +1159,8 @@ impl EditorView {
let editor = &mut cxt.editor;
if let Some((pos, view_id)) = pos_and_view(editor, row, column, true) {
+ editor.focus(view_id);
+
let prev_view_id = view!(editor).id;
let doc = doc_mut!(editor, &view!(editor, view_id).doc);
@@ -1182,7 +1184,6 @@ impl EditorView {
self.clear_completion(editor);
}
- editor.focus(view_id);
editor.ensure_cursor_in_view(view_id);
return EventResult::Consumed(None);
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) {