From cdee8cafd8797b8196ddad1427d10501c3148ad1 Mon Sep 17 00:00:00 2001 From: Steven Guh Date: Mon, 22 Nov 2021 21:29:27 -0800 Subject: [PATCH] Add an option to control display of menu buttons --- CHANGELOG.md | 4 ++-- package.json | 7 ++++++- src/config/menuConfig.ts | 1 + src/constants.ts | 2 ++ src/menu/baseWhichKeyMenu.ts | 4 +++- src/menu/whichKeyMenu.ts | 1 + src/test/suite/menu/whichkeyMenu.test.ts | 2 ++ src/whichKeyCommand.ts | 5 ++++- 8 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceddee1..542d18a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add command (`whichkey.undoKey`) to undo entered key. -- Add menu buttons to which key menu. -- Added three additional sorting options +- Add menu buttons to which key menu (Use `whichkey.showButtons` in config to turn on/off). +- Add three additional sorting options - `custom`: Menu items are sorted by the key in the following 'categories' then by a custom order within each 'category'. diff --git a/package.json b/package.json index e8e0f0a..4730432 100644 --- a/package.json +++ b/package.json @@ -228,7 +228,12 @@ }, "whichkey.showIcons": { "type": "boolean", - "markdownDescription": "Controls whether to show or hide icons in which-key menu.", + "markdownDescription": "Controls whether to show or hide icons in the which-key menu.", + "default": true + }, + "whichkey.showButtons": { + "type": "boolean", + "markdownDescription": "Controls whether to show or hide buttons in the which-key menu.", "default": true }, "whichkey.sortOrder": { diff --git a/src/config/menuConfig.ts b/src/config/menuConfig.ts index 849e348..af0019c 100644 --- a/src/config/menuConfig.ts +++ b/src/config/menuConfig.ts @@ -7,6 +7,7 @@ export interface WhichKeyMenuConfig { title?: string; delay: number; showIcons: boolean; + showButtons: boolean; bindings: BindingItem[]; } diff --git a/src/constants.ts b/src/constants.ts index 991e147..029d634 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -3,6 +3,7 @@ export const contributePrefix = 'whichkey'; export enum ConfigKey { Delay = "delay", ShowIcons = "showIcons", + ShowButtons = "showButtons", SortOrder = "sortOrder", Bindings = "bindings", Overrides = "bindingOverrides", @@ -38,6 +39,7 @@ export enum ContextKey { export const Configs = { Delay: `${contributePrefix}.${ConfigKey.Delay}`, ShowIcons: `${contributePrefix}.${ConfigKey.ShowIcons}`, + ShowButtons: `${contributePrefix}.${ConfigKey.ShowButtons}`, SortOrder: `${contributePrefix}.${ConfigKey.SortOrder}`, Bindings: `${contributePrefix}.${ConfigKey.Bindings}`, Overrides: `${contributePrefix}.${ConfigKey.Overrides}`, diff --git a/src/menu/baseWhichKeyMenu.ts b/src/menu/baseWhichKeyMenu.ts index cda0ad6..9a006d8 100644 --- a/src/menu/baseWhichKeyMenu.ts +++ b/src/menu/baseWhichKeyMenu.ts @@ -40,6 +40,8 @@ export abstract class BaseWhichKeyMenu implement onDidResolve?: () => any; onDidReject?: (reason?: any) => any; + showButtons = true; + constructor(cmdRelay: CommandRelay) { this._acceptQueue = new DispatchQueue(this.handleAcceptanceDispatch.bind(this)); this._valueQueue = new DispatchQueue(this.handleValueDispatch.bind(this)); @@ -280,7 +282,7 @@ export abstract class BaseWhichKeyMenu implement update(state: BaseWhichKeyMenuState): void { this.clearDelay(); this._qp.title = state.title; - this._qp.buttons = state.buttons ?? []; + this._qp.buttons = this.showButtons ? state.buttons ?? [] : []; // Need clear the current rendered menu items // when user click the back button with delay // so we won't show the old menu items while the menu is diff --git a/src/menu/whichKeyMenu.ts b/src/menu/whichKeyMenu.ts index 518a0ad..53e13bd 100644 --- a/src/menu/whichKeyMenu.ts +++ b/src/menu/whichKeyMenu.ts @@ -191,6 +191,7 @@ export function showWhichKeyMenu(statusBar: StatusBar, cmdRelay: CommandRelay, r const menu = new WhichKeyMenu(statusBar, cmdRelay, repeater); menu.delay = config.delay; menu.showIcons = config.showIcons; + menu.showButtons = config.showButtons; menu.update({ items: config.bindings, title: config.title, diff --git a/src/test/suite/menu/whichkeyMenu.test.ts b/src/test/suite/menu/whichkeyMenu.test.ts index af651eb..41fbe19 100644 --- a/src/test/suite/menu/whichkeyMenu.test.ts +++ b/src/test/suite/menu/whichkeyMenu.test.ts @@ -24,6 +24,7 @@ suite("WhichKeyMenu", function () { const config: WhichKeyMenuConfig = { delay: 0, showIcons: false, + showButtons: false, title: "Test", bindings: [ { @@ -60,6 +61,7 @@ suite("WhichKeyMenu", function () { const config: WhichKeyMenuConfig = { delay: 0, showIcons: false, + showButtons: false, title: "Test", bindings: [ { diff --git a/src/whichKeyCommand.ts b/src/whichKeyCommand.ts index 3154f9a..2dc4505 100644 --- a/src/whichKeyCommand.ts +++ b/src/whichKeyCommand.ts @@ -251,10 +251,12 @@ export default class WhichKeyCommand { show(): void { const delay = getConfig(Configs.Delay) ?? 0; const showIcons = getConfig(Configs.ShowIcons) ?? true; + const showButtons = getConfig(Configs.ShowButtons) ?? true; const config = { bindings: this.bindingItems!, delay, showIcons, + showButtons, title: this.config?.title }; showWhichKeyMenu(this.statusBar, this.cmdRelay, this.repeater, config); @@ -271,7 +273,8 @@ export default class WhichKeyCommand { static show(bindings: BindingItem[], statusBar: StatusBar, cmdRelay: CommandRelay): void { const delay = getConfig(Configs.Delay) ?? 0; const showIcons = getConfig(Configs.ShowIcons) ?? true; - const config = { bindings, delay, showIcons }; + const showButtons = getConfig(Configs.ShowButtons) ?? true; + const config = { bindings, delay, showIcons, showButtons }; showWhichKeyMenu(statusBar, cmdRelay, undefined, config); } }