From a5f31162f6a23fbaacf08eff27cf4d00c9a46fc1 Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 3 Dec 2017 00:20:42 +0300 Subject: [PATCH] de-htmlize showKeymapHelp --- edit.html | 27 +++++++++++++++++++++++++++ edit/show-keymap-help.js | 31 +++++++++++++++++-------------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/edit.html b/edit.html index a5e2286f..008a8cc7 100644 --- a/edit.html +++ b/edit.html @@ -85,11 +85,13 @@ + + + + + + + + + + + + diff --git a/edit/show-keymap-help.js b/edit/show-keymap-help.js index 7326784c..8c73cbfa 100644 --- a/edit/show-keymap-help.js +++ b/edit/show-keymap-help.js @@ -8,26 +8,29 @@ onDOMready().then(() => { function showKeyMapHelp() { const keyMap = mergeKeyMaps({}, prefs.get('editor.keyMap'), CodeMirror.defaults.extraKeys); const keyMapSorted = Object.keys(keyMap) - .map(key => ({key: key, cmd: keyMap[key]})) + .map(key => ({key, cmd: keyMap[key]})) .concat([{key: 'Shift-Ctrl-Wheel', cmd: 'scrollWindow'}]) .sort((a, b) => (a.cmd < b.cmd || (a.cmd === b.cmd && a.key < b.key) ? -1 : 1)); - showHelp(t('cm_keyMap') + ': ' + prefs.get('editor.keyMap'), - '' + - '' + - '' + - '' + keyMapSorted.map(value => - '' - ).join('') + - '' + - '
' + value.key + '' + value.cmd + '
'); + const table = template.keymapHelp.cloneNode(true); + const tBody = table.tBodies[0]; + const row = tBody.rows[0]; + const cellA = row.children[0]; + const cellB = row.children[1]; + tBody.textContent = ''; + for (const {key, cmd} of keyMapSorted) { + cellA.textContent = key; + cellB.textContent = cmd; + tBody.appendChild(row.cloneNode(true)); + } - const table = $('#help-popup table'); - table.addEventListener('input', filterTable); + showHelp(t('cm_keyMap') + ': ' + prefs.get('editor.keyMap'), table); const inputs = $$('input', table); inputs[0].addEventListener('keydown', hotkeyHandler); inputs[1].focus(); + table.oninput = filterTable; + function hotkeyHandler(event) { const keyName = CodeMirror.keyName(event); if (keyName === 'Esc' || keyName === 'Tab' || keyName === 'Shift-Tab') { @@ -48,7 +51,7 @@ function showKeyMapHelp() { const input = event.target; const col = input.parentNode.cellIndex; inputs[1 - col].value = ''; - table.tBodies[0].childNodes.forEach(row => { + for (const row of tBody.rows) { const cell = row.children[col]; const text = cell.textContent; const query = stringAsRegExp(input.value, 'gi'); @@ -76,7 +79,7 @@ function showKeyMapHelp() { const text = otherCell.textContent; otherCell.textContent = text; } - }); + } } function mergeKeyMaps(merged, ...more) { more.forEach(keyMap => {