Skip to content

Commit

Permalink
Merge pull request #1089 from Dyalog/kb-shortcuts
Browse files Browse the repository at this point in the history
Refactor keyboard shortcuts preferences page, fix #959
  • Loading branch information
e9gille authored Aug 15, 2023
2 parents efd7f33 + 9984992 commit 985c913
Show file tree
Hide file tree
Showing 8 changed files with 1,010 additions and 966 deletions.
114 changes: 57 additions & 57 deletions src/cmds.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
D.cmds = [
/* eslint-disable */
//code description default keys
['ABT','About Dyalog', ['Shift-F1']],
['ABT','About Dyalog', ['Shift+F1']],
['AC', 'Align comments', []],
['AO', 'Comment out lines', []],
['ASW', 'Auto Status', []],
['BH', 'Run to exit (in tracer)', []],
['BK', 'Backward or Undo', ['Ctrl-Shift-Backspace']],
['BK', 'Backward or Undo', ['Ctrl+Shift+Backspace']],
['BP', 'Toggle breakpoint', []],
['BT', 'Back Tab between windows',['Ctrl-Shift-Tab']],
['BT', 'Back Tab between windows',['Ctrl+Shift+Tab']],
['CAM','Clear all trace/stop/monitor',[]],
['CAW','Close All Windows',[]],
['CBP','Clear stops for active object',[]],
Expand All @@ -26,59 +26,59 @@ D.cmds = [
['DMR','Load demo file', []],
['DOX','Documentation Centre', []],
['DO', 'Uncomment lines', []],
['ED', 'Edit', ['Shift-Enter']],
['ED', 'Edit', ['Shift+Enter']],
['EP', 'Exit (and save changes)', ['Escape']],
['ER', 'Execute line', ['Enter']],
['EXP','Expand selection', ['Alt-Shift-Up']],
['FD', 'Forward or Redo', ['Ctrl-Shift-Enter']],
['EXP','Expand selection', [D.mac?'Shift+Option+Up':'Shift+Alt+Up']],
['FD', 'Forward or Redo', ['Ctrl+Shift+Enter']],
['FX', 'Fix the current function',[]],
['HLP','Help', ['F1']],
['JBK','Jump back', ['Ctrl-Shift-J']],
['JBK','Jump back', ['Ctrl+Shift+J']],
['JSC','Show JavaScript console', ['F12']],
['LBR','Toggle language bar', []],
['LL', 'Left Limit', ['Home']],
['LN', 'Toggle line numbers', []],
['LOG','Show RIDE protocol log', ['Ctrl-F12']],
['LOG','Show RIDE protocol log', ['Ctrl+F12']],
['MA', 'Continue execution of all threads',[]],
['NEW','New session', [D.mac?'Cmd-N':'Ctrl-N']],
['NEW','New session', [D.mac?'Cmd+N':'Ctrl+N']],
['NX' ,'Next match', []],
['OWS','Open Workspace', [D.mac?'Cmd-O':'Ctrl-O']],
['OWS','Open Workspace', [D.mac?'Cmd+O':'Ctrl+O']],
['PAT','Pause all Threads', []],
['POE','Pause on Error', []],
['PRF','Show preferences', []],
['PV' ,'Previous match', []],
['QCP','Quick Command Palette', []],
['QIT','Quit', (D.mac?['Cmd-Q']:[]).concat('Ctrl-Q')],
['QT', 'Close window (and lose changes)',['Shift-Escape']],
['QIT','Quit', [D.mac?'Cmd+Q':'Ctrl+Q']],
['QT', 'Close window (and lose changes)',['Shift+Escape']],
['RD', 'Reformat', ['NumPad_Divide']],
['RDO', 'Redo', (D.mac?['Shift-Cmd-Z']:[]).concat('Ctrl-Y')],
['RDO', 'Redo', [D.mac?'Shift+Cmd+Z':'Ctrl+Y']],
['RP', 'Replace', []],
['RL', 'Right Limit', ['End']],
['RM', 'Continue execution of this thread', []],
['UAT','Unpause all paused threads',[]],
['SA', 'Select All', [D.mac?'Cmd-A':'Ctrl-A']],
['SC', 'Search', ['Ctrl-F']],
['SA', 'Select All', [D.mac?'Cmd+A':'Ctrl+A']],
['SC', 'Search', ['Ctrl+F']],
['SI', 'Strong interrupt', []],
['SBR','Toggle status bar', []],
['SSW','Toggle status window', []],
['STL','Skip to line', []],
['TB', 'Tab between windows', ['Ctrl-Tab']],
['TC', 'Trace line', ['Ctrl-Enter']],
['TB', 'Tab between windows', ['Ctrl+Tab']],
['TC', 'Trace line', ['Ctrl+Enter']],
['TGC','Toggle comment', []],
['TIP','Show value tip', []],
['TL', 'Toggle localisation', ['Ctrl-Up']],
['TL', 'Toggle localisation', ['Ctrl+Up']],
['TO', 'Toggle fold', []],
['TVB','Toggle view stops', []],
['TVO','Toggle view outline', []],
['TFR', 'Refresh threads', []],
['UND', 'Undo', (D.mac?['Cmd-Z']:[]).concat('Ctrl-Z')],
['UND', 'Undo', [D.mac?'Cmd+Z':'Ctrl+Z']],
['VAL','Evaluate selection or name under cursor',[]],
['WI', 'Weak interrupt', ['Ctrl-PauseBreak']],
['WI', 'Weak interrupt', ['Ctrl+PauseBreak']],
['WSE','Toggle workspace explorer',[]],
['ZM', 'Toggle maximise editor', []],
['ZMI','Increase font size', (D.mac?['Cmd-=','Shift-Cmd-=']:[]).concat(['Ctrl-=','Ctrl-Shift-='])],
['ZMO','Decrease font size', (D.mac?['Cmd--']:[]).concat('Ctrl--')],
['ZMR','Reset font size', (D.mac?['Cmd-0']:[]).concat('Ctrl-0')],
['ZMI','Increase font size', [D.mac?'Cmd+=':'Ctrl+=']],
['ZMO','Decrease font size', [D.mac?'Cmd+-':'Ctrl+-']],
['ZMR','Reset font size', [D.mac?'Cmd+0':'Ctrl+0']],
['PF1' ,'', []],
['PF2' ,'', ['F2']],
['PF3' ,'', ['F3']],
Expand All @@ -92,40 +92,40 @@ D.cmds = [
['PF11','', []],
['PF12','', []],
['PF13','', []],
['PF14','', ['Shift-F2']],
['PF15','', ['Shift-F3']],
['PF16','', ['Shift-F4']],
['PF17','', ['Shift-F5']],
['PF18','', ['Shift-F6']],
['PF19','', ['Shift-F7']],
['PF20','', ['Shift-F8']],
['PF21','', ['Shift-F9']],
['PF22','', ['Shift-F10']],
['PF23','', ['Shift-F11']],
['PF24','', ['Shift-F12']],
['PF25','', ['Ctrl-F1']],
['PF26','', ['Ctrl-F2']],
['PF27','', ['Ctrl-F3']],
['PF28','', ['Ctrl-F4']],
['PF29','', ['Ctrl-F5']],
['PF30','', ['Ctrl-F6']],
['PF31','', ['Ctrl-F7']],
['PF32','', ['Ctrl-F8']],
['PF33','', ['Ctrl-F9']],
['PF34','', ['Ctrl-F10']],
['PF35','', ['Ctrl-F11']],
['PF14','', ['Shift+F2']],
['PF15','', ['Shift+F3']],
['PF16','', ['Shift+F4']],
['PF17','', ['Shift+F5']],
['PF18','', ['Shift+F6']],
['PF19','', ['Shift+F7']],
['PF20','', ['Shift+F8']],
['PF21','', ['Shift+F9']],
['PF22','', ['Shift+F10']],
['PF23','', ['Shift+F11']],
['PF24','', ['Shift+F12']],
['PF25','', ['Ctrl+F1']],
['PF26','', ['Ctrl+F2']],
['PF27','', ['Ctrl+F3']],
['PF28','', ['Ctrl+F4']],
['PF29','', ['Ctrl+F5']],
['PF30','', ['Ctrl+F6']],
['PF31','', ['Ctrl+F7']],
['PF32','', ['Ctrl+F8']],
['PF33','', ['Ctrl+F9']],
['PF34','', ['Ctrl+F10']],
['PF35','', ['Ctrl+F11']],
['PF36','', []],
['PF37','', ['Ctrl-Shift-F1']],
['PF38','', ['Ctrl-Shift-F2']],
['PF39','', ['Ctrl-Shift-F3']],
['PF40','', ['Ctrl-Shift-F4']],
['PF41','', ['Ctrl-Shift-F5']],
['PF42','', ['Ctrl-Shift-F6']],
['PF43','', ['Ctrl-Shift-F7']],
['PF44','', ['Ctrl-Shift-F8']],
['PF45','', ['Ctrl-Shift-F9']],
['PF46','', ['Ctrl-Shift-F10']],
['PF47','', ['Ctrl-Shift-F11']],
['PF48','', ['Ctrl-Shift-F12']],
['PF37','', ['Ctrl+Shift+F1']],
['PF38','', ['Ctrl+Shift+F2']],
['PF39','', ['Ctrl+Shift+F3']],
['PF40','', ['Ctrl+Shift+F4']],
['PF41','', ['Ctrl+Shift+F5']],
['PF42','', ['Ctrl+Shift+F6']],
['PF43','', ['Ctrl+Shift+F7']],
['PF44','', ['Ctrl+Shift+F8']],
['PF45','', ['Ctrl+Shift+F9']],
['PF46','', ['Ctrl+Shift+F10']],
['PF47','', ['Ctrl+Shift+F11']],
['PF48','', ['Ctrl+Shift+F12']],
/* eslint-enable */
];
7 changes: 4 additions & 3 deletions src/km.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,15 @@
const km = monaco.KeyMod;
const ctrlcmd = {
Ctrl: D.mac ? km.WinCtrl : km.CtrlCmd,
Cmd: km.CtrlCmd,
Win: km.CtrlCmd,
Cmd: D.mac ? km.CtrlCmd : km.WinCtrl,
Option: km.Alt,
Win: km.WinCtrl,
Meta: km.CtrlCmd,
};
const stlkbs = [];
const fxkbs = [];
function monacoKeyBinding(ks) {
return ks.replace(/-(.)/g, '\n$1').split('\n').reduce((a, ko) => {
return ks.replace(/\+(.)/g, '\n$1').split('\n').reduce((a, ko) => {
const k = D.keyMap.labels[ko] || ko;
return a | (ctrlcmd[k] || km[k] || kc[k]); // eslint-disable-line no-bitwise
}, 0);
Expand Down
48 changes: 33 additions & 15 deletions src/prf_shc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
const updDups = () => { // check for duplicates and make them show in red
const a = q.tbl_wr.querySelectorAll('.shc_text');
const h = {}; // h:maps keystrokes to jQuery objects
for (let i = 0; i < a.length; i++) {
const k = a[i].textContent;
a[i].className = h[k] ? (h[k].className = 'shc_text shc_dup') : 'shc_text';
h[k] = a[i];
}
[...a].forEach((k) => {
const t = k.title;
k.classList.toggle('shc_dup', !!h[t]) && h[t].classList.add('shc_dup');
h[t] = k;
});
};
const getKeystroke = (b, f) => { // b:"+" button,f:callback
const e = document.createElement('div');
Expand All @@ -22,10 +22,15 @@
const kn = monaco.KeyCode[x.keyCode];
const be = x.browserEvent;
const isMeta = meta.has(kn);
const s = (be.ctrlKey ? 'Ctrl-' : '') + (be.altKey ? 'Alt-' : '')
+ (be.shiftKey && (be.type === 'keydown' || be.which) ? 'Shift-' : '')
+ (be.metaKey ? 'Cmd-' : '')
+ (isMeta ? '' : D.keyMap.labels[kn]);
const s = [
x.ctrlKey ? 'Ctrl' : '',
x.shiftKey && (be.type === 'keydown' || be.which) ? 'Shift' : '',
// eslint-disable-next-line no-nested-ternary
x.altKey ? (D.mac ? 'Option' : 'Alt') : '',
// eslint-disable-next-line no-nested-ternary
x.metaKey ? (D.mac ? 'Cmd' : (D.win ? 'Win' : 'Meta')) : '',
isMeta ? '' : D.keyMap.labels[kn],
].filter((k) => k).join('+');
me.setValue(s || 'Press keystroke...');
if (!isMeta) {
r = (x.keyCode === monaco.KeyCode.KEY_IN_COMPOSITION || !D.keyMap.labels[kn]) ? '' : s;
Expand Down Expand Up @@ -62,10 +67,20 @@
b.parentNode.insertBefore(e, b);
me.focus();
};
const keyHTML = (x) => (
`<span class=shc_key><span class=shc_text>${x}</span>`
+ '<a href=# class=shc_del title="Remove shortcut">×</a></span> '
);
const keyLabels = {
Ctrl: '⌃',
Shift: '⇧',
Option: '⌥',
Cmd: '⌘',
};
const keyHTML = (x) => {
const keys = x.replace(/\+(.)/g, '\n$1').split('\n');
const btns = keys.map((k) => (
`<div class=shc_key_btn>${D.mac ? (keyLabels[k] || k) : k}</div>`
)).join('+');
return `<span class=shc_key><span class=shc_text title="${keys.join('+')}">${btns}</span>`
+ '<a href=# class=shc_del title="Remove shortcut">×</a></span> ';
};
const updSC = () => {
const a = q.tbl_wr.querySelectorAll('tr');
const s = q.sc.value.toLowerCase();
Expand Down Expand Up @@ -177,7 +192,10 @@
load() { loadFrom(D.prf.keys()); },
validate() {
const dup = q.tbl_wr.getElementsByClassName('shc_dup');
if (dup.length) return { msg: 'Duplicate shortcuts', el: dup[0] };
if (dup.length) {
dup[0].scrollIntoViewIfNeeded();
return { msg: 'Duplicate shortcuts', el: dup[0] };
}
return null;
},
print() {
Expand All @@ -192,7 +210,7 @@
let shortcuts = a[i].querySelectorAll('[class^=shc_text]');
const keys = [];
if (shortcuts.length) {
shortcuts = shortcuts.forEach((e) => { keys.push(e.innerHTML); });
shortcuts = shortcuts.forEach((e) => { keys.push(e.title); });
}
h[cmdName] = keys;
}
Expand Down
Loading

0 comments on commit 985c913

Please sign in to comment.