Advertisement
dhniceday

Untitled

Jan 25th, 2023
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```dataviewjs
  2.  
  3. const getNestedObject = (nestedObj, pathArr) => {
  4.     return pathArr.reduce((obj, key) =>
  5.         (obj && obj[key] !== 'undefined') ? obj[key] : undefined, nestedObj);
  6. }
  7.  
  8. function hilite(keys, how) {
  9.     // need to check if existing key combo is overridden by undefining it
  10.     if (keys && keys[1][0] !== undefined) {
  11.         return how + keys.flat(2).join('+').replace('Mod', 'Ctrl') + how;
  12.     } else {
  13.         return how + '–' + how;
  14.     }
  15. }
  16.  
  17. function getHotkey(arr, highlight=true) {
  18.     let hi = highlight ? '**' : '';
  19.     let defkeys = arr.hotkeys ? [[getNestedObject(arr.hotkeys, [0, 'modifiers'])],
  20.     [getNestedObject(arr.hotkeys, [0, 'key'])]] : undefined;
  21.     let ck = app.hotkeyManager.customKeys[arr.id];
  22.     var hotkeys = ck ? [[getNestedObject(ck, [0, 'modifiers'])], [getNestedObject(ck, [0, 'key'])]] : undefined;
  23.     return hotkeys ? hilite(hotkeys, hi) : hilite(defkeys, '');
  24. }
  25.  
  26. let cmds = dv.array(Object.entries(app.commands.commands))
  27.     .where(v => getHotkey(v[1]) != '–')
  28.     .sort(v => v[1].id, 'asc')
  29.     .sort(v => getHotkey(v[1], false), 'asc');
  30.  
  31. dv.paragraph(cmds.length + " commands with assigned hotkeys; " +
  32.     "non-default hotkeys <strong>bolded</strong>.<br><br>");
  33.  
  34. dv.table(["Command ID", "Name in current locale", "Hotkeys"],
  35.   cmds.map(v => [
  36.     v[1].id,
  37.     v[1].name,
  38.     getHotkey(v[1]),
  39.     ])
  40.   );
  41. ```
  42.  
  43. ### Commands sorted by Command ID
  44.  
  45. ```dataviewjs
  46.  
  47. const getNestedObject = (nestedObj, pathArr) => {
  48.     return pathArr.reduce((obj, key) =>
  49.         (obj && obj[key] !== 'undefined') ? obj[key] : undefined, nestedObj);
  50. }
  51.  
  52. function hilite(keys, how) {
  53.     // need to check if existing key combo is overridden by undefining it
  54.     if (keys && keys[1][0] !== undefined) {
  55.         return how + keys.flat(2).join('+').replace('Mod', 'Ctrl') + how;
  56.     } else {
  57.         return how + '–' + how;
  58.     }
  59. }
  60.  
  61. function getHotkey(arr, highlight=true) {
  62.     let hi = highlight ? '**' : '';
  63.     let defkeys = arr.hotkeys ? [[getNestedObject(arr.hotkeys, [0, 'modifiers'])],
  64.     [getNestedObject(arr.hotkeys, [0, 'key'])]] : undefined;
  65.     let ck = app.hotkeyManager.customKeys[arr.id];
  66.     var hotkeys = ck ? [[getNestedObject(ck, [0, 'modifiers'])], [getNestedObject(ck, [0, 'key'])]] : undefined;
  67.     return hotkeys ? hilite(hotkeys, hi) : hilite(defkeys, '');
  68. }
  69.  
  70. let cmds = dv.array(Object.entries(app.commands.commands))
  71.     .sort(v => v[1].id, 'asc');
  72.  
  73. dv.paragraph(cmds.length + " commands currently enabled; " +
  74.     "non-default hotkeys <strong>bolded</strong>.<br><br>");
  75.  
  76. dv.table(["Command ID", "Name in current locale", "Hotkeys"],
  77.   cmds.map(v => [
  78.     v[1].id,
  79.     v[1].name,
  80.     getHotkey(v[1]),
  81.     ])
  82.   );
  83. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement