From 7ea72632b8fc6190b0b7a6153ab904af5f7747b1 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 5 Jul 2021 09:59:03 +0200 Subject: [PATCH] display keyboard shortcuts in button widget title --- src/public/app/widgets/buttons/button_widget.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/public/app/widgets/buttons/button_widget.js b/src/public/app/widgets/buttons/button_widget.js index 0426c8758..25da03883 100644 --- a/src/public/app/widgets/buttons/button_widget.js +++ b/src/public/app/widgets/buttons/button_widget.js @@ -1,9 +1,14 @@ import NoteContextAwareWidget from "../note_context_aware_widget.js"; +import keyboardActionsService from "../../services/keyboard_actions.js"; const TPL = ``; +let actions; + +keyboardActionsService.getActions().then(as => actions = as); + export default class ButtonWidget extends NoteContextAwareWidget { isEnabled() { return true; @@ -30,7 +35,17 @@ export default class ButtonWidget extends NoteContextAwareWidget { this.$widget.tooltip({ html: true, - title: () => this.settings.title, + title: () => { + const title = this.settings.title; + const action = actions.find(act => act.actionName === this.settings.command); + + if (action && action.effectiveShortcuts.length > 0) { + return `${title} (${action.effectiveShortcuts.join(", ")})`; + } + else { + return title; + } + }, trigger: "hover" });