mirror of
https://github.com/dragonwocky/obsidian-tray.git
synced 2025-12-04 06:40:14 +11:00
Merge e3de313bdd into ac353bb5a6
This commit is contained in:
commit
0531973148
@ -30,6 +30,9 @@ Hotkeys can be assigned to the commands via Obsidian's built-in hotkey manager.
|
||||
| Quick note location | New quick notes will be placed in this folder. | |
|
||||
| Quick note date format | New quick notes will use a filename of this pattern. Format: [Moment.js format string](https://momentjs.com/docs/#/displaying/format/) | `YYYY-MM-DD` |
|
||||
| Quick note hotkey | This hotkey is registered globally and will be detected even if Obsidian does not have keyboard focus. Format: [Electron accelerator](https://www.electronjs.org/docs/latest/tutorial/keyboard-shortcuts#accelerators) | <kbd>CmdOrCtrl+Shift+Q</kbd> |
|
||||
| Quick note always create | If a quick note with the same name already exists, create a new numbered file. Disable to open the existing file instead. | Enabled |
|
||||
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
34
main.js
34
main.js
@ -159,7 +159,7 @@ const cleanup = () => {
|
||||
};
|
||||
|
||||
const addQuickNote = () => {
|
||||
const { quickNoteLocation, quickNoteDateFormat } = plugin.settings,
|
||||
const { quickNoteLocation, quickNoteDateFormat, quickNoteAlwaysCreate } = plugin.settings,
|
||||
pattern = quickNoteDateFormat || DEFAULT_DATE_FORMAT,
|
||||
date = obsidian.moment().format(pattern),
|
||||
name = obsidian
|
||||
@ -172,11 +172,24 @@ const addQuickNote = () => {
|
||||
// set to "same folder as current file")
|
||||
leaf = plugin.app.workspace.getLeaf(),
|
||||
root = plugin.app.fileManager.getNewFileParent(""),
|
||||
openMode = { active: true, state: { mode: "source" } };
|
||||
plugin.app.fileManager
|
||||
.createNewMarkdownFile(root, name)
|
||||
.then((file) => leaf.openFile(file, openMode));
|
||||
showWindows();
|
||||
openMode = { active: true, state: { mode: "source" } },
|
||||
filePath = `${name}.md`;
|
||||
if (quickNoteAlwaysCreate) {
|
||||
plugin.app.fileManager
|
||||
.createNewMarkdownFile(root, name)
|
||||
.then((file) => leaf.openFile(file, openMode))
|
||||
.then(() => showWindows());
|
||||
} else {
|
||||
const existing = plugin.app.vault.getAbstractFileByPath(filePath);
|
||||
if (existing && existing instanceof obsidian.TFile) {
|
||||
leaf.openFile(existing, openMode).then(() => showWindows());
|
||||
} else {
|
||||
plugin.app.fileManager
|
||||
.createNewMarkdownFile(root, name)
|
||||
.then((file) => leaf.openFile(file, openMode))
|
||||
.then(() => showWindows());
|
||||
}
|
||||
}
|
||||
},
|
||||
replaceVaultName = (str) => {
|
||||
return str.replace(/{{vault}}/g, plugin.app.vault.getName());
|
||||
@ -358,6 +371,15 @@ const OPTIONS = [
|
||||
onBeforeChange: unregisterHotkeys,
|
||||
onChange: registerHotkeys,
|
||||
},
|
||||
{
|
||||
key: "quickNoteAlwaysCreate",
|
||||
desc: `
|
||||
If a quick note with the same name already exists, create a new numbered file.
|
||||
Disable to open the existing file instead.
|
||||
`,
|
||||
type: "toggle",
|
||||
default: true,
|
||||
},
|
||||
];
|
||||
|
||||
const keyToLabel = (key) =>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user