diff options
author | Gabriel Dinner-David | 2024-01-09 01:21:16 +0000 |
---|---|---|
committer | GitHub | 2024-01-09 01:21:16 +0000 |
commit | 84e24b33dcda16d1d64805f34dcc02d82d0de8f1 (patch) | |
tree | a7aaf60d67bc0a71d48aaae1d245ea329388a143 /helix-view | |
parent | 65d041288067f1d1bbcf659c8b73ae04d77afb02 (diff) |
make sure to sync views when applying edits to unfocused views (#9173)
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/editor.rs | 24 |
1 files changed, 24 insertions, 0 deletions
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) { |