From ae964032a24221c6b93c3bbbd8b04b4cfb4d3214 Mon Sep 17 00:00:00 2001 From: Filipe Azevedo Date: Thu, 10 Nov 2022 17:12:06 +0000 Subject: [PATCH] refresh all views cursors --- helix-term/src/commands/typed.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 0ed7adca13b82..05b4b3180957c 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1049,34 +1049,44 @@ fn reload_all( view.id }; - let docs_views: Vec<(DocumentId, ViewId)> = cx + let docs_views: Vec<(DocumentId, Vec)> = cx .editor .documents_mut() .map(|doc| { - let target_view = if doc.selections().contains_key(&view_id) { - view_id - } else if let Some(view) = doc.selections().keys().next() { - *view - } else { + let mut views: Vec<_> = doc.selections().keys().cloned().collect(); + + if views.is_empty() { doc.ensure_view_init(view_id); - view_id + views = vec![view_id]; }; - (doc.id(), target_view) + (doc.id(), views) }) .collect(); - for (doc_id, view_id) in docs_views { - let view = view_mut!(cx.editor, view_id); + for (doc_id, view_ids) in docs_views { let doc = doc_mut!(cx.editor, &doc_id); + let mut view_ids = view_ids.into_iter(); + + // Every doc is guaranteed to have at least 1 view at this point. + let view_id = view_ids.next().unwrap(); + let view = view_mut!(cx.editor, view_id); + doc.reload(view).map(|_| { view.ensure_cursor_in_view(doc, scrolloff); })?; + + for view_id in view_ids { + let view = view_mut!(cx.editor, view_id); + + view.ensure_cursor_in_view(doc, scrolloff); + } } Ok(()) } + /// Update the [`Document`] if it has been modified. fn update( cx: &mut compositor::Context,