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: show all commands in palette help, make prefix stand out #2689

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion lapce-app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2212,8 +2212,26 @@ fn palette_item(
} else {
vec![]
};
let prefix = if let PaletteItemContent::PaletteHelp { prefix, .. } =
item.content
{
label(move || prefix).style(move |s| {
s.padding_horiz(5.0)
.padding_vert(1.0)
.margin_right(5.0)
.font_family(config.get().editor.font_family.clone())
.apply_if(!prefix.is_empty(), |s| {
s.border(1.0).border_radius(3.0).border_color(
*config.get().get_color(LapceColor::LAPCE_BORDER),
)
})
})
} else {
label(move || "")
};
container_box(
stack((
prefix,
focus_text(
move || text.clone(),
move || indices.clone(),
Expand Down Expand Up @@ -2353,7 +2371,7 @@ fn palette_content(
let workspace = workspace.clone();
let keymap = {
let cmd_kind = match &item.content {
PaletteItemContent::PaletteHelp { cmd } => {
PaletteItemContent::PaletteHelp { prefix: _, cmd } => {
Some(CommandKind::Workbench(cmd.clone()))
}
PaletteItemContent::Command {
Expand Down
26 changes: 7 additions & 19 deletions lapce-app/src/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,28 +380,16 @@ impl PaletteData {
/// Initialize the palette with a list of the available palette kinds.
fn get_palette_help(&self) {
let items = PaletteKind::iter()
.filter_map(|kind| {
// Don't include PaletteHelp as the user is already here.
(kind != PaletteKind::PaletteHelp)
.then(|| {
let symbol = kind.symbol();

// Only include palette kinds accessible by typing a prefix into the
// palette.
(kind == PaletteKind::File || !symbol.is_empty())
.then_some(kind)
})
.flatten()
})
.filter_map(|kind| kind.command().map(|cmd| (kind, cmd)))
.map(|(kind, cmd)| {
let description = kind.symbol().to_string()
+ " "
+ cmd.get_message().unwrap_or("");
let description = cmd.get_message().unwrap_or("");

PaletteItem {
content: PaletteItemContent::PaletteHelp { cmd },
filter_text: description,
content: PaletteItemContent::PaletteHelp {
prefix: kind.symbol(),
cmd,
},
filter_text: description.to_owned(),
score: 0,
indices: vec![],
}
Expand Down Expand Up @@ -936,7 +924,7 @@ impl PaletteData {
self.close();
if let Some(item) = items.get(index) {
match &item.content {
PaletteItemContent::PaletteHelp { cmd } => {
PaletteItemContent::PaletteHelp { prefix: _, cmd } => {
let cmd = LapceCommand {
kind: CommandKind::Workbench(cmd.clone()),
data: None,
Expand Down
1 change: 1 addition & 0 deletions lapce-app/src/palette/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct PaletteItem {
#[derive(Clone, Debug, PartialEq)]
pub enum PaletteItemContent {
PaletteHelp {
prefix: &'static str,
cmd: LapceWorkbenchCommand,
},
File {
Expand Down