notes with #keyboardShortcut don't need reload to take effect

This commit is contained in:
zadam
2022-12-01 13:24:34 +01:00
parent fc080f785b
commit 7aa801fc1f
4 changed files with 34 additions and 26 deletions

View File

@@ -2,18 +2,39 @@ import appContext from "./app_context.js";
import shortcutService from "../services/shortcuts.js";
import server from "../services/server.js";
import Component from "./component.js";
import froca from "../services/froca.js";
export default class ShortcutComponent extends Component {
constructor() {
super();
server.get('keyboard-shortcuts-for-notes').then(shortcutAttributes => {
for (const attr in shortcutAttributes) {
bindNoteShortcutHandler(attr);
for (const attr of shortcutAttributes) {
this.bindNoteShortcutHandler(attr);
}
});
}
bindNoteShortcutHandler(attr) {
const handler = async () => appContext.tabManager.getActiveContext().setNote(attr.noteId);
const handler = () => appContext.tabManager.getActiveContext().setNote(attr.noteId);
const namespace = attr.attributeId;
shortcutService.bindGlobalShortcut(attr.value, handler, attr.attributeId);
if (attr.isDeleted) {
shortcutService.removeGlobalShortcut(namespace);
} else {
shortcutService.bindGlobalShortcut(attr.value, handler, namespace);
}
}
async entitiesReloadedEvent({loadResults}) {
for (const attr of loadResults.getAttributes()) {
if (attr.type === 'label' && attr.name === 'keyboardShortcut') {
const note = await froca.getNote(attr.noteId);
// launcher shortcuts are handled specifically
if (note && note.type !== 'launcher') {
this.bindNoteShortcutHandler(attr);
}
}
}
}
}