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

60
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)
@ -2557,18 +2541,34 @@ function mainkeydownhandler()
} }
else else
{ {
commands.filter(c => c.shortcut) // notes shortcuts
.every(command => var note = localdata.find(n =>
{ {
var s = splitshortcut(command.shortcut); var shortcut = n.content.match(/shortcut: (.*)/);
if (event.key == s.key && !(s.ctrl && !event.ctrlKey && !event.altKey) && !(s.shift && !event.shiftKey)) if (shortcut)
{ {
event.preventDefault(); console.log("Loading note '" + n.title + "' from header shortcut " + shortcut[1]);
executecommand(command); loadnote(n.title);
return false; return shortcutmatches(event, shortcut[1]);
} }
return true; return false;
}); });
// commands shortcuts
if (!note)
{
commands.filter(c => c.shortcut)
.every(command =>
{
if (shortcutmatches(event, command.shortcut))
{
event.preventDefault();
executecommand(command);
return false;
}
return true;
});
}
} }
} }