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

Allow ordinary menus #353

Merged
merged 9 commits into from
Apr 11, 2025
Merged

Allow ordinary menus #353

merged 9 commits into from
Apr 11, 2025

Conversation

jwhitaker-gridcog
Copy link
Contributor

@jwhitaker-gridcog jwhitaker-gridcog commented Dec 17, 2024

Heya, thanks for maintaining this.

When playing with Strackeror's great Helix mode contribution, I was having trouble getting a command-hx menu to feel right due to the single hot key system. E.g. distilled to a three item menu, "fmt / Format", "w / Write", and "wbc / Write and Close", w and wbc can't be distinguished in the current system.

As a proof of concept, I wondered if menus could have a menu_type: "hotkey" (current behaviour, and default) or alternatively a menu_type: "palette", which is just a stock-standard vscode quickpick. Palette menus don't have the hotkey system but can just use vscode's already great type/select system which I've been using locally quite happily.

Demo:

Kooha-2024-12-18-08-42-33.webm.mp4
From menus config:
    "dance.menus": {
        "leader-hx": {
            "title": "Space",
            "items": {
                "f": {
                    "text": "Open file picker",
                    "command": "workbench.action.quickOpen"
                }
            }
        },
        "command-hx": {
            "title": "Helix command mode",
            "menu_type": "palette",
            "items": {
                "fmt": {
                    "text": "format",
                    "command": "editor.action.formatDocument"
                },
                "w": {
                    "text": "write",
                    "command": "workbench.action.files.save"
                },
                // "wbc": {
                //     "text": "write-buffer-close",
                //     "command": "dance.run",
                //     "args": [
                //         {
                //             "commands": [
                //                 "workbench.action.files.save",
                //                 "workbench.action.closeeditor"
                //             ]
                //         }
                //     ]
                // }
            }
        }
    },

This probably isn't wired up the best way, but was hoping to get some feedback on if this would be accepted in principal or not before fiddling further.

Thanks!

@Strackeror
Copy link
Contributor

Ooooh, that's a great way to do a simple command palette, I'm stealing this for my fork :)

Copy link
Owner

@71 71 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! From what I see it should be easy to merge.

@jwhitaker-gridcog jwhitaker-gridcog requested a review from 71 February 22, 2025 15:57
@jwhitaker-gridcog
Copy link
Contributor Author

camel_case exorcized, description/help text added to jsonschema, and more efficient "what was picked?" implemented. thanks for review!

package.build.ts Outdated
},
{
const: "hotkey",
description: "A `hotkey` menu is used to give a menu and keybinds emulating Helix's multi-key Static Commands, e.g. [g]oto → [e]nd."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this should be a kakoune example sorry, will fix up when I get a chance

Copy link
Owner

@71 71 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Feel free to take your time if you want to improve documentation or something.

src/api/menu.ts Outdated
const choice = await promptOne(items, (quickPick) => quickPick.title = menu.title);

let choice: string | number;
if ((menu.menuType ?? 'hotkey') == 'hotkey') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (sorry):

Suggested change
if ((menu.menuType ?? 'hotkey') == 'hotkey') {
if ((menu.menuType ?? 'hotkey') === 'hotkey') {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No stress, thanks for picking up.
A general note: you seem to put a lot of effort into making sure contributions follow good+consistent code style. This is fine but probably means thorough review takes a lot of your time!

Would you consider setting up a linter to automate this? Things like Biome are amazingly fast these days, and as a contributor it means I can check (and sometimes even autofix!) these things before you even need to read them.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great point! I really need (and want) to set this up, but haven't done so yet. Nowadays I mostly work with Deno, so I'll need to either migrate existing lints to Deno or learn other linters and formatters. I similarly want to adopt a new code style (damn me, having to always "Save Without Formatting" in VS Code), but that requires applying it to the whole repo and breaking pending PRs.

package.build.ts Outdated
description: "A `hotkey` menu is used to give a menu and keybinds emulating Helix's multi-key Static Commands, e.g. [g]oto → [e]nd."
}
],
description: 'meny type test',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh oops! Soz

package.build.ts Outdated
@@ -361,6 +361,20 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
title: {
type: "string",
},
menuType: {
anyOf: [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyOf is more of an "advanced" JSON Schema feature. In VS Code markdownEnumDescriptions is better supported.

@jwhitaker-gridcog
Copy link
Contributor Author

jwhitaker-gridcog commented Feb 23, 2025

should be good now, sorry I'm not sure if you want you or me to resolve the feedback so I'll leave to you :)

EDIT: following on from the linter discussion above, I ran eslint for the first time.. i hadn't done this, oops. This raised that the typescript satisfies operator I'm using isn't supported on the dance's Typescript version. I've hence included a commit to bump typescript to the latest. Same commit includes two small fixups - newer typescript gets stressed out by functions with mixed implicit and explicit returns. I can bump this off if requested, but new Typescript is probably desirable.

@jwhitaker-gridcog
Copy link
Contributor Author

Is this one waiting on anything from me? Apart from maybe removing 'wip' from the title :)

@jwhitaker-gridcog jwhitaker-gridcog changed the title wip: allow ordinary menus Allow ordinary menus Mar 13, 2025
Copy link
Owner

@71 71 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I've hence included a commit to bump typescript to the latest

Sounds good, thanks.

Two small comments and then I'll approve.

@@ -165,7 +187,7 @@ export async function showMenuAfterDelay(
const pickedItem = menu.items[itemKeys],
args = mergeArgs(pickedItem.args, additionalArgs);

return Context.WithoutActiveEditor.wrap(
await Context.WithoutActiveEditor.wrap(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be followed by a return statement (unless that's intentional?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eep, great catch thanks.

package.build.ts Outdated
@@ -361,6 +361,18 @@ export const pkg = (modules: Builder.ParsedModule[]) => ({
title: {
type: "string",
},
menuType: {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I only think about this now, but what about type? menu.menuType: palette is a bit redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@jwhitaker-gridcog
Copy link
Contributor Author

fixed up, ta.
I've snuck on one more commit on the end - it hooks up autocomplete for commands when the user edits their menu configs. :) I can pop this off and PR separately if you'd prefer, but it's a trivial one-liner so in here for now :)

image

@jwhitaker-gridcog jwhitaker-gridcog requested a review from 71 April 9, 2025 22:37
@71
Copy link
Owner

71 commented Apr 11, 2025

@jwhitaker-gridcog Thank you!

it hooks up autocomplete for commands when the user edits their menu configs

Works great, thanks!

@71 71 merged commit 4e3d259 into 71:master Apr 11, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants