Allow users to open folder notes in a new tab with ctrl

This commit is contained in:
Lost Paul 2023-05-02 16:38:42 +02:00
parent 08c1218a40
commit 38a5fdfe89
2 changed files with 6 additions and 7 deletions

View file

@ -39,7 +39,7 @@ export class Commands {
item.setTitle('Delete folder note')
.setIcon('trash')
.onClick(() => {
file = this.plugin.app.vault.getAbstractFileByPath(file?.path + '/' + file?.name + '.md') as TFile;
file = this.plugin.app.vault.getAbstractFileByPath(file.path + '/' + file.name + '.md') ?? file;
if (!(file instanceof TFile)) return;
this.plugin.deleteFolderNote(file);
});
@ -49,7 +49,7 @@ export class Commands {
item.setTitle('Create folder note')
.setIcon('edit')
.onClick(() => {
this.plugin.createFolderNote(file.path + '/' + file.name + '.md' , true);
this.plugin.createFolderNote(file.path + '/' + file.name + '.md', true);
});
});
}

View file

@ -138,7 +138,7 @@ export default class FolderNotesPlugin extends Plugin {
const path = folder + '/' + event.target.innerText + '.md';
if (this.app.vault.getAbstractFileByPath(path)) {
return this.openFolderNote(path);
return this.openFolderNote(path, event);
} else if (event.altKey || Keymap.isModEvent(event) === 'tab') {
if ((this.settings.altKey && event.altKey) || (this.settings.ctrlKey && Keymap.isModEvent(event) === 'tab')) {
await this.createFolderNote(path, true, true);
@ -155,7 +155,6 @@ export default class FolderNotesPlugin extends Plugin {
if (!(event.target instanceof HTMLElement)) return;
if (!this.settings.openFolderNoteOnClickInPath) return;
const folder = event.target.getAttribute('data-path');
console.log(folder);
if (!folder) { return; }
const excludedFolder = this.getExcludedFolderByPath(folder);
if (excludedFolder?.disableFolderNote) {
@ -169,7 +168,7 @@ export default class FolderNotesPlugin extends Plugin {
const path = folder + '/' + event.target.innerText + '.md';
if (this.app.vault.getAbstractFileByPath(path)) {
return this.openFolderNote(path);
return this.openFolderNote(path, event);
} else if (event.altKey || Keymap.isModEvent(event) === 'tab') {
if ((this.settings.altKey && event.altKey) || (this.settings.ctrlKey && Keymap.isModEvent(event) === 'tab')) {
await this.createFolderNote(path, true, true);
@ -293,8 +292,8 @@ export default class FolderNotesPlugin extends Plugin {
this.addCSSClassToTitleEL(path, 'is-folder-note', true);
}
async openFolderNote(path: string) {
const leaf = this.app.workspace.getLeaf(false);
async openFolderNote(path: string, evt: MouseEvent) {
const leaf = this.app.workspace.getLeaf(Keymap.isModEvent(evt));
const file = this.app.vault.getAbstractFileByPath(path);
if (file instanceof TFile) {
await leaf.openFile(file);