Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUESTION: Any way to query the Sequence hotkey list? #15

Open
drventure opened this issue Oct 31, 2022 · 2 comments
Open

QUESTION: Any way to query the Sequence hotkey list? #15

drventure opened this issue Oct 31, 2022 · 2 comments

Comments

@drventure
Copy link

For instance, I can query the system hotkey list with the DataView plugin using
Object.entries(app.commands.commands)

Is there anything similar for the Sequence Hotkeys? What I'd like to do is query BOTH, then merge the lists and present +all+ defined hotkeys in one filterable list....

@moolmanruan
Copy link
Owner

I'm not sure what information gets exposed to other plugins by Obsidian, but I will install the DataView plugin some time and have a look.

@drventure
Copy link
Author

Sure thing. Also, the whole dataview block I'm using looks like this. Just paste it into a note somewhere

const getNestedObject = (nestedObj, pathArr) => 
{ 
	return pathArr.reduce((obj, key) => (obj && obj[key] !== 'undefined') ? obj[key] : undefined, nestedObj); 
}

function getHotkey(arr) { 
return arr.hotkeys ? [[getNestedObject(arr.hotkeys, [0, 'modifiers'])], 
					  [getNestedObject(arr.hotkeys, [0, 'key'])]].flat(2) 
					  .join(' ') 
					  .replace('Mod', 'Ctrl') 
					  //.replace('Shift', 'Shift') 
					  //.replace('Alt', 'Alt') 
					  //.replace('Ctrl', 'Ctrl') 
					  .replace('ArrowRight', 'Right') 
					  .replace('ArrowLeft', 'Left') 
					  .replace('ArrowUp', 'Up') 
					  .replace('ArrowDown', 'Down') 
					  .replace('Enter', '⏎') 
					  //.replace('Tab', '⇥') 
					  : '–'; }

let cmds = dv.array(Object.entries(app.commands.commands)).sort(v => v[1].id, 'asc'); 
cmds = cmds.map(v => [ v[1].id, v[1].name, getHotkey(v[1]), ]);
//filter for only items with hotkeys
cmds = cmds.filter(v => v[2] != '–' && v[2] >= 'A');
//order by hotkey (the 3'rd value in each object in the list)
cmds = cmds.sort(v => v[2], 'asc');
dv.paragraph(cmds.length + " commands currently enabled.<br><br>"); 
dv.table(["Command ID", "Name in current locale", "Hotkeys"], 
		 cmds);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants