Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Picker titles #12520

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2565,7 +2565,8 @@ fn global_search(cx: &mut Context) {
Some((path.as_path().into(), Some((*line_num, *line_num))))
})
.with_history_register(Some(reg))
.with_dynamic_query(get_files, Some(275));
.with_dynamic_query(get_files, Some(275))
.with_title("Global Search");

cx.push_layer(Box::new(overlaid(picker)));
}
Expand Down Expand Up @@ -3049,7 +3050,8 @@ fn buffer_picker(cx: &mut Context) {
(cursor_line, cursor_line)
});
Some((meta.id.into(), lines))
});
})
.with_title("Buffers");
cx.push_layer(Box::new(overlaid(picker)));
}

Expand Down Expand Up @@ -3140,7 +3142,8 @@ fn jumplist_picker(cx: &mut Context) {
let doc = &editor.documents.get(&meta.id)?;
let line = meta.selection.primary().cursor_line(doc.text().slice(..));
Some((meta.id.into(), Some((line, line))))
});
})
.with_title("Jump List");
cx.push_layer(Box::new(overlaid(picker)));
}

Expand Down Expand Up @@ -3222,7 +3225,8 @@ fn changed_file_picker(cx: &mut Context) {
}
},
)
.with_preview(|_editor, meta| Some((meta.path().into(), None)));
.with_preview(|_editor, meta| Some((meta.path().into(), None)))
.with_title("Changed Files");
let injector = picker.injector();

cx.editor
Expand Down Expand Up @@ -3314,7 +3318,8 @@ pub fn command_palette(cx: &mut Context) {
doc.append_changes_to_history(view);
}
}
});
})
.with_title("Commands");
compositor.push(Box::new(overlaid(picker)));
},
));
Expand Down
17 changes: 14 additions & 3 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ fn diag_picker(
},
)
.with_preview(move |_editor, diag| location_to_file_location(&diag.location))
.with_title("Diagnostics")
.truncate_start(false)
}

Expand Down Expand Up @@ -414,6 +415,7 @@ pub fn symbol_picker(cx: &mut Context) {
},
)
.with_preview(move |_editor, item| location_to_file_location(&item.location))
.with_title("Document Symbols")
.truncate_start(false);

compositor.push(Box::new(overlaid(picker)))
Expand Down Expand Up @@ -526,6 +528,7 @@ pub fn workspace_symbol_picker(cx: &mut Context) {
)
.with_preview(|_editor, item| location_to_file_location(&item.location))
.with_dynamic_query(get_symbols, None)
.with_title("Workspace Symbols")
.truncate_start(false);

cx.push_layer(Box::new(overlaid(picker)));
Expand Down Expand Up @@ -854,6 +857,7 @@ impl Display for ApplyEditErrorKind {

/// Precondition: `locations` should be non-empty.
fn goto_impl(
title: &str,
editor: &mut Editor,
compositor: &mut Compositor,
locations: Vec<Location>,
Expand Down Expand Up @@ -883,7 +887,8 @@ fn goto_impl(
let picker = Picker::new(columns, 0, locations, cwdir, move |cx, location, action| {
jump_to_location(cx.editor, location, offset_encoding, action)
})
.with_preview(move |_editor, location| location_to_file_location(location));
.with_preview(move |_editor, location| location_to_file_location(location))
.with_title(title);
compositor.push(Box::new(overlaid(picker)));
}
}
Expand Down Expand Up @@ -928,7 +933,13 @@ where
if items.is_empty() {
editor.set_error("No definition found.");
} else {
goto_impl(editor, compositor, items, offset_encoding);
goto_impl(
"Goto Implementation",
editor,
compositor,
items,
offset_encoding,
);
}
},
);
Expand Down Expand Up @@ -996,7 +1007,7 @@ pub fn goto_reference(cx: &mut Context) {
if items.is_empty() {
editor.set_error("No references found.");
} else {
goto_impl(editor, compositor, items, offset_encoding);
goto_impl("Goto Reference", editor, compositor, items, offset_encoding);
}
},
);
Expand Down
3 changes: 2 additions & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,8 @@ fn lsp_workspace_command(
move |cx, (ls_id, command), _action| {
execute_lsp_command(cx.editor, *ls_id, command.clone());
},
);
)
.with_title("LSP Commands");
compositor.push(Box::new(overlaid(picker)))
},
));
Expand Down
3 changes: 2 additions & 1 deletion helix-term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ pub fn file_picker(root: PathBuf, config: &helix_view::editor::Config) -> FilePi
cx.editor.set_error(err);
}
})
.with_preview(|_editor, path| Some((path.as_path().into(), None)));
.with_preview(|_editor, path| Some((path.as_path().into(), None)))
.with_title("Files");
let injector = picker.injector();
let timeout = std::time::Instant::now() + std::time::Duration::from_millis(30);

Expand Down
17 changes: 13 additions & 4 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ pub struct Picker<T: 'static + Send + Sync, D: 'static> {
/// An event handler for syntax highlighting the currently previewed file.
preview_highlight_handler: Sender<Arc<Path>>,
dynamic_query_handler: Option<Sender<DynamicQueryChange>>,
title: Option<String>,
}

impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
Expand Down Expand Up @@ -380,6 +381,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
file_fn: None,
preview_highlight_handler: PreviewHighlightHandler::<T, D>::default().spawn(),
dynamic_query_handler: None,
title: None,
}
}

Expand All @@ -399,6 +401,11 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
self
}

pub fn with_title(mut self, title: &str) -> Self {
self.title = Some(title.to_string());
self
}

pub fn with_preview(
mut self,
preview_fn: impl for<'a> Fn(&'a Editor, &'a T) -> Option<FileLocation<'a>> + 'static,
Expand Down Expand Up @@ -640,12 +647,14 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {
let background = cx.editor.theme.get("ui.background");
surface.clear_with(area, background);

const BLOCK: Block<'_> = Block::bordered();
let block: Block<'_> = self.title.as_ref().map_or(Block::bordered(), |title| {
Block::bordered().title(title.to_string())
});

// calculate the inner area inside the box
let inner = BLOCK.inner(area);
let inner = block.inner(area);

BLOCK.render(area, surface);
block.render(area, surface);

// -- Render the input bar:

Expand Down Expand Up @@ -934,7 +943,7 @@ impl<T: 'static + Send + Sync, D: 'static + Send + Sync> Picker<T, D> {

impl<I: 'static + Send + Sync, D: 'static + Send + Sync> Component for Picker<I, D> {
fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
// +---------+ +---------+
// +--title--+ +---------+
// |prompt | |preview |
// +---------+ | |
// |picker | | |
Expand Down
Loading