fixed: avoid execute action from palette if not saved
refactor: change savedonly to allowunsaved
This commit is contained in:
parent
f75c7b6bd2
commit
db1aad06cd
65
main.js
65
main.js
|
@ -99,108 +99,92 @@ var commands = [
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+p",
|
shortcut: "ctrl+p",
|
||||||
hint: "Show notes list",
|
hint: "Show notes list",
|
||||||
savedonly: true,
|
|
||||||
action: searchandloadnote
|
action: searchandloadnote
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Share note",
|
hint: "Share note",
|
||||||
savedonly: true,
|
|
||||||
action: share
|
action: share
|
||||||
}/*,
|
}/*,
|
||||||
{
|
{
|
||||||
hint: "Share note (html)",
|
hint: "Share note (html)",
|
||||||
savedonly: true,
|
|
||||||
action: sharehtml
|
action: sharehtml
|
||||||
}*/,
|
}*/,
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+n",
|
shortcut: "ctrl+n",
|
||||||
hint: "New note",
|
hint: "New note",
|
||||||
savedonly: true,
|
|
||||||
action: startnewnote
|
action: startnewnote
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+shift+P",
|
shortcut: "ctrl+shift+P",
|
||||||
hint: "Command palette",
|
hint: "Command palette",
|
||||||
savedonly: false,
|
allowunsaved: true,
|
||||||
action: commandpalette,
|
action: commandpalette,
|
||||||
excludepalette: true
|
excludepalette: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+t",
|
shortcut: "ctrl+t",
|
||||||
hint: "Open todo",
|
hint: "Open todo",
|
||||||
savedonly: true,
|
|
||||||
action: loadtodo
|
action: loadtodo
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+q",
|
shortcut: "ctrl+q",
|
||||||
hint: "Open quick note",
|
hint: "Open quick note",
|
||||||
savedonly: true,
|
|
||||||
action: loadquicknote
|
action: loadquicknote
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+g",
|
shortcut: "ctrl+g",
|
||||||
hint: "Find in notes",
|
hint: "Find in notes",
|
||||||
savedonly: true,
|
|
||||||
action: showgrep
|
action: showgrep
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+i",
|
shortcut: "ctrl+i",
|
||||||
hint: "Toggle title",
|
hint: "Toggle title",
|
||||||
savedonly: true,
|
|
||||||
action: toggletitle
|
action: toggletitle
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+m",
|
shortcut: "ctrl+m",
|
||||||
hint: "Toggle preview",
|
hint: "Toggle preview",
|
||||||
savedonly: true,
|
|
||||||
action: togglepreview
|
action: togglepreview
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+d",
|
shortcut: "ctrl+d",
|
||||||
hint: "Delete note",
|
hint: "Delete note",
|
||||||
savedonly: true,
|
|
||||||
action: deletenote
|
action: deletenote
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Restore note",
|
hint: "Restore note",
|
||||||
savedonly: true,
|
|
||||||
action: restore
|
action: restore
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
shortcut: "ctrl+h",
|
shortcut: "ctrl+h",
|
||||||
hint: "Insert markdown header",
|
hint: "Insert markdown header",
|
||||||
action: insertheader
|
action: insertheader,
|
||||||
|
allowunsaved: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
savedonly: true,
|
|
||||||
shortcut: "F1",
|
shortcut: "F1",
|
||||||
hint: "Show help",
|
hint: "Show help",
|
||||||
action: showhelp
|
action: showhelp
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
savedonly: true,
|
|
||||||
shortcut: "ctrl+shift+C",
|
shortcut: "ctrl+shift+C",
|
||||||
hint: "Fold",
|
hint: "Fold",
|
||||||
action: fold
|
action: fold
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
savedonly: true,
|
|
||||||
shortcut: "ctrl+shift+O",
|
shortcut: "ctrl+shift+O",
|
||||||
hint: "Unfold",
|
hint: "Unfold",
|
||||||
action: unfold
|
action: unfold
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
savedonly: true,
|
|
||||||
hint: "Unfold all",
|
hint: "Unfold all",
|
||||||
action: unfoldall
|
action: unfoldall
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
savedonly: true,
|
|
||||||
hint: "Download note",
|
hint: "Download note",
|
||||||
action: downloadnote
|
action: downloadnote
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
savedonly: true,
|
|
||||||
hint: "Download local data",
|
hint: "Download local data",
|
||||||
action: downloadlocal,
|
action: downloadlocal,
|
||||||
shortcut: "ctrl+shift+S"
|
shortcut: "ctrl+shift+S"
|
||||||
|
@ -208,54 +192,44 @@ var commands = [
|
||||||
{
|
{
|
||||||
hint: "Search tags",
|
hint: "Search tags",
|
||||||
action: searchtags,
|
action: searchtags,
|
||||||
savedonly: true,
|
|
||||||
shortcut: "ctrl+shift+T"
|
shortcut: "ctrl+shift+T"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Log out",
|
hint: "Log out",
|
||||||
action: logout,
|
action: logout,
|
||||||
savedonly: true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Toggle split view",
|
hint: "Toggle split view",
|
||||||
savedonly: true,
|
|
||||||
action: togglesplit
|
action: togglesplit
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Load previous note",
|
hint: "Load previous note",
|
||||||
savedonly: true,
|
|
||||||
action: loadprevious,
|
action: loadprevious,
|
||||||
shortcut: "ctrl+b"
|
shortcut: "ctrl+b"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Sort text",
|
hint: "Sort text",
|
||||||
savedonly: true,
|
|
||||||
action: sortselection
|
action: sortselection
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Settings",
|
hint: "Settings",
|
||||||
savedonly: true,
|
|
||||||
action: editsettings
|
action: editsettings
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Restore default settings",
|
hint: "Restore default settings",
|
||||||
savedonly: true,
|
|
||||||
action: restoresettings
|
action: restoresettings
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Note outline",
|
hint: "Note outline",
|
||||||
savedonly: true,
|
|
||||||
action: showoutline,
|
action: showoutline,
|
||||||
shortcut: "ctrl+o"
|
shortcut: "ctrl+o"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Internal links",
|
hint: "Internal links",
|
||||||
savedonly: true,
|
|
||||||
action: showinternallinks
|
action: showinternallinks
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Switch vault",
|
hint: "Switch vault",
|
||||||
savedonly: true,
|
|
||||||
action: switchvault,
|
action: switchvault,
|
||||||
shortcut: "ctrl+shift+V"
|
shortcut: "ctrl+shift+V"
|
||||||
},
|
},
|
||||||
|
@ -263,22 +237,22 @@ var commands = [
|
||||||
hint: "Add tag filter",
|
hint: "Add tag filter",
|
||||||
action: addtagfilter,
|
action: addtagfilter,
|
||||||
shortcut: "ctrl+shift+F",
|
shortcut: "ctrl+shift+F",
|
||||||
savedonly: true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Select theme",
|
hint: "Select theme",
|
||||||
savedonly: true,
|
|
||||||
action: selecttheme
|
action: selecttheme
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Show note info",
|
hint: "Show note info",
|
||||||
action: showinfo,
|
action: showinfo,
|
||||||
shortcut: "ctrl+w"
|
shortcut: "ctrl+w",
|
||||||
|
allowunsaved: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hint: "Force save",
|
hint: "Force save",
|
||||||
action: save,
|
action: save,
|
||||||
shortcut: "ctrl+s"
|
shortcut: "ctrl+s",
|
||||||
|
allowunsaved: true
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var snippets = [
|
var snippets = [
|
||||||
|
@ -1207,9 +1181,9 @@ function commandpalette()
|
||||||
.then(hint =>
|
.then(hint =>
|
||||||
{
|
{
|
||||||
var command = commands.find(c => c.hint == hint);
|
var command = commands.find(c => c.hint == hint);
|
||||||
if (command && command.action)
|
if (command)
|
||||||
{
|
{
|
||||||
command.action();
|
executecommand(command);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1582,6 +1556,18 @@ function splitshortcut(s)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function executecommand(command)
|
||||||
|
{
|
||||||
|
if (!command.allowunsaved && !saved)
|
||||||
|
{
|
||||||
|
showtemporaryinfo("Cannot perform '" + command.hint + "' because current note is not saved.");
|
||||||
|
}
|
||||||
|
else if (command.action)
|
||||||
|
{
|
||||||
|
command.action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function mainkeydownhandler()
|
function mainkeydownhandler()
|
||||||
{
|
{
|
||||||
if (event.key == "Escape")
|
if (event.key == "Escape")
|
||||||
|
@ -1619,14 +1605,7 @@ function mainkeydownhandler()
|
||||||
if (event.key == s.key && !(s.ctrl && !event.ctrlKey && !event.altKey) && !(s.shift && !event.shiftKey))
|
if (event.key == s.key && !(s.ctrl && !event.ctrlKey && !event.altKey) && !(s.shift && !event.shiftKey))
|
||||||
{
|
{
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (command.savedonly && !saved)
|
executecommand(command);
|
||||||
{
|
|
||||||
showtemporaryinfo("Cannot perform '" + command.hint + "' because current note is not saved.");
|
|
||||||
}
|
|
||||||
else if (command.action)
|
|
||||||
{
|
|
||||||
command.action();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue