Skip to content

Commit

Permalink
refresh all views cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas committed Nov 13, 2022
1 parent 537faed commit bff93a4
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,39 +1044,46 @@ fn reload_all(
}

let scrolloff = cx.editor.config().scrolloff;
let view_id = {
let (view, _) = current_ref!(cx.editor);
view.id
};
let view_id = view!(cx.editor).id;

let docs_views: Vec<(DocumentId, ViewId)> = cx
let docs_views: Vec<(DocumentId, Vec<ViewId>)> = 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,
Expand Down

0 comments on commit bff93a4

Please sign in to comment.