From 917174e546ca20e13538510a700c7c80f759d12c Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 7 Jan 2025 14:59:44 -0500 Subject: [PATCH] Fix blank buffer picker preview on doc with no views Reproduction: * `hx` * Open any file in a split (`f` and choose anything with ``) * Close the split with `q` * Open up the buffer picker and look the file you opened previously Previously the preview was empty in this case because the Document's `selections` hashmap was empty and we returned early, giving `None` instead of a FileLocation. Instead when the Document is not currently open in any view we can show the document but with no range highlighted. --- helix-term/src/commands.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index a93fa445..3c93ae7f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3044,12 +3044,11 @@ fn buffer_picker(cx: &mut Context) { }) .with_preview(|editor, meta| { let doc = &editor.documents.get(&meta.id)?; - let &view_id = doc.selections().keys().next()?; - let line = doc - .selection(view_id) - .primary() - .cursor_line(doc.text().slice(..)); - Some((meta.id.into(), Some((line, line)))) + let lines = doc.selections().values().next().map(|selection| { + let cursor_line = selection.primary().cursor_line(doc.text().slice(..)); + (cursor_line, cursor_line) + }); + Some((meta.id.into(), lines)) }); cx.push_layer(Box::new(overlaid(picker))); }