From af64ec4ac083f56b6b67ecaddf597a93f6dea9e6 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 26 Nov 2017 15:08:47 +0300 Subject: [PATCH] show a real hotkey in Save button tooltip --- edit.html | 2 +- edit/edit.js | 31 +++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/edit.html b/edit.html index c13e3c75..b5297fbb 100644 --- a/edit.html +++ b/edit.html @@ -156,7 +156,7 @@
- +
diff --git a/edit/edit.js b/edit/edit.js index 79397945..2e18a96d 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -12,6 +12,7 @@ onDOMready() .then(() => Promise.all([ initColorpicker(), initCollapsibles(), + initHooksCommon(), ])) .then(init); @@ -1480,7 +1481,6 @@ function initHooks() { $('#keyMap-help').addEventListener('click', showKeyMapHelp, false); $('#cancel-button').addEventListener('click', goBackToManage); - initCollapsibles(); initLint(); if (!FIREFOX) { @@ -1493,14 +1493,33 @@ function initHooks() { ).forEach(e => e.addEventListener('mousedown', toggleContextMenuDelete)); } - window.addEventListener('load', function _() { - window.removeEventListener('load', _); - window.addEventListener('resize', () => debounce(rememberWindowSize, 100)); - }); - setupGlobalSearch(); } +// common for usercss and classic +function initHooksCommon() { + showKeyInSaveButtonTooltip(); + prefs.subscribe(['editor.keyMap'], showKeyInSaveButtonTooltip); + window.addEventListener('resize', () => debounce(rememberWindowSize, 100)); + + function showKeyInSaveButtonTooltip(prefName, value) { + $('#save-button').title = findKeyForCommand('save', value); + } + function findKeyForCommand(command, mapName = CodeMirror.defaults.keyMap) { + const map = CodeMirror.keyMap[mapName]; + let key = Object.keys(map).find(k => map[k] === command); + if (key) { + return key; + } + for (const ft of Array.isArray(map.fallthrough) ? map.fallthrough : [map.fallthrough]) { + key = ft && findKeyForCommand(command, ft); + if (key) { + return key; + } + } + return ''; + } +} function toggleContextMenuDelete(event) { if (chrome.contextMenus && event.button === 2 && prefs.get('editor.contextDelete')) {