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:
parent
62851f91f8
commit
7bb607753e
48
main.js
48
main.js
|
@ -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)
|
||||
|
@ -2556,12 +2540,27 @@ function mainkeydownhandler()
|
|||
event.preventDefault();
|
||||
}
|
||||
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)
|
||||
.every(command =>
|
||||
{
|
||||
var s = splitshortcut(command.shortcut);
|
||||
if (event.key == s.key && !(s.ctrl && !event.ctrlKey && !event.altKey) && !(s.shift && !event.shiftKey))
|
||||
if (shortcutmatches(event, command.shortcut))
|
||||
{
|
||||
event.preventDefault();
|
||||
executecommand(command);
|
||||
|
@ -2571,6 +2570,7 @@ function mainkeydownhandler()
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setwindowtitle()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue