From 84e24b33dcda16d1d64805f34dcc02d82d0de8f1 Mon Sep 17 00:00:00 2001 From: Gabriel Dinner-David Date: Mon, 8 Jan 2024 20:21:16 -0500 Subject: make sure to sync views when applying edits to unfocused views (#9173) --- helix-view/src/editor.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'helix-view/src') diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index c018668c..f13df213 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1910,6 +1910,30 @@ impl Editor { .as_ref() .and_then(|debugger| debugger.current_stack_frame()) } + + /// Returns the id of a view that this doc contains a selection for, + /// making sure it is synced with the current changes + /// if possible or there are no selections returns current_view + /// otherwise uses an arbitrary view + pub fn get_synced_view_id(&mut self, id: DocumentId) -> ViewId { + let current_view = view_mut!(self); + let doc = self.documents.get_mut(&id).unwrap(); + if doc.selections().contains_key(¤t_view.id) { + // only need to sync current view if this is not the current doc + if current_view.doc != id { + current_view.sync_changes(doc); + } + current_view.id + } else if let Some(view_id) = doc.selections().keys().next() { + let view_id = *view_id; + let view = self.tree.get_mut(view_id); + view.sync_changes(doc); + view_id + } else { + doc.ensure_view_init(current_view.id); + current_view.id + } + } } fn try_restore_indent(doc: &mut Document, view: &mut View) { -- cgit v1.2.3-70-g09d2