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