fixed: notes with shortcut now override command

changed: notes with shortcuts are no longer in command palette (all notes are included)
This commit is contained in:
quenousimporte 2023-10-03 13:37:30 +02:00
parent 62851f91f8
commit 7bb607753e
1 changed files with 30 additions and 30 deletions

48
main.js
View File

@ -1345,7 +1345,6 @@ function loadstorage()
{ {
loadlast(); loadlast();
} }
initshortcuts();
} }
function applystyle() function applystyle()
@ -1425,27 +1424,6 @@ function initvault()
currentvault = window.localStorage.getItem("vault") || "local"; currentvault = window.localStorage.getItem("vault") || "local";
} }
function initshortcuts()
{
localdata
.filter(n => n.content.includes("shortcut: "))
.forEach(n => {
var hint = "Open " + n.title;
if (!commands.find(c => c.hint == hint))
{
var shortcut = n.content.match(/shortcut: (.*)/)[1];
commands.push({
hint: hint,
shortcut: shortcut,
action: function()
{
loadnote(n.title);
}
});
}
});
}
function addfakehistory() function addfakehistory()
{ {
history.pushState({}, '', '.'); history.pushState({}, '', '.');
@ -2465,6 +2443,12 @@ function splitshortcut(s)
return r; return r;
} }
function shortcutmatches(event, shortcut)
{
var s = splitshortcut(shortcut);
return (event.key == s.key && !(s.ctrl && !event.ctrlKey && !event.altKey) && !(s.shift && !event.shiftKey))
}
function executecommand(command) function executecommand(command)
{ {
if (!command.allowunsaved && !saved) if (!command.allowunsaved && !saved)
@ -2556,12 +2540,27 @@ function mainkeydownhandler()
event.preventDefault(); event.preventDefault();
} }
else else
{
// notes shortcuts
var note = localdata.find(n =>
{
var shortcut = n.content.match(/shortcut: (.*)/);
if (shortcut)
{
console.log("Loading note '" + n.title + "' from header shortcut " + shortcut[1]);
loadnote(n.title);
return shortcutmatches(event, shortcut[1]);
}
return false;
});
// commands shortcuts
if (!note)
{ {
commands.filter(c => c.shortcut) commands.filter(c => c.shortcut)
.every(command => .every(command =>
{ {
var s = splitshortcut(command.shortcut); if (shortcutmatches(event, command.shortcut))
if (event.key == s.key && !(s.ctrl && !event.ctrlKey && !event.altKey) && !(s.shift && !event.shiftKey))
{ {
event.preventDefault(); event.preventDefault();
executecommand(command); executecommand(command);
@ -2570,6 +2569,7 @@ function mainkeydownhandler()
return true; return true;
}); });
} }
}
} }
function setwindowtitle() function setwindowtitle()