MacOS cmd + click support

This commit is contained in:
Lost Paul 2023-03-28 10:58:36 +02:00
parent 08ece2293c
commit ece9b16014
3 changed files with 20 additions and 16 deletions

View file

@ -1,4 +1,4 @@
import { Plugin, TFile, TFolder, TAbstractFile, Notice } from 'obsidian';
import { Plugin, TFile, TFolder, TAbstractFile, Notice, Keymap } from 'obsidian';
import { DEFAULT_SETTINGS, FolderNotesSettings, SettingsTab } from './settings';
import FolderNameModal from './modals/folderName';
import { applyTemplate } from './template';
@ -175,7 +175,6 @@ export default class FolderNotesPlugin extends Plugin {
event.target.click();
}
const path = folder + '/' + event.target.innerText + '.md';
if (this.app.vault.getAbstractFileByPath(path)) {
event.target.classList.remove('has-not-folder-note');
event.target.classList.add('has-folder-note');
@ -189,9 +188,11 @@ export default class FolderNotesPlugin extends Plugin {
}
});
} else if (event.altKey || event.ctrlKey) {
if ((this.settings.altKey && event.altKey) || (this.settings.ctrlKey && event.ctrlKey)) {
} else if (event.altKey || Keymap.isModEvent(event) == 'tab') {
if ((this.settings.altKey && event.altKey) || (this.settings.ctrlKey && Keymap.isModEvent(event) == 'tab')) {
this.createFolderNote(path, true, true);
event.target.classList.remove('has-not-folder-note');
event.target.classList.add('has-folder-note');
if (!this.settings.hideFolderNote) return;
event.target.parentElement?.parentElement?.getElementsByClassName('nav-folder-children').item(0)?.querySelectorAll('div.nav-file')
.forEach((element: HTMLElement) => {

View file

@ -120,16 +120,19 @@ export class SettingsTab extends PluginSettingTab {
.setName('Key for creating folder note')
.setDesc('The key combination to create a folder note')
.addDropdown((dropdown) => {
dropdown
.addOption('ctrl', 'Ctrl + Click')
.addOption('alt', 'Alt + Click')
.setValue(this.plugin.settings.ctrlKey ? 'ctrl' : 'alt')
.onChange(async (value) => {
this.plugin.settings.ctrlKey = value === 'ctrl';
this.plugin.settings.altKey = value === 'alt';
await this.plugin.saveSettings();
this.display();
});
if(!Platform.isMacOS) {
dropdown.addOption('ctrl', 'Ctrl + Click')
} else {
dropdown.addOption('ctrl', 'Cmd + Click')
}
dropdown.addOption('alt', 'Alt + Click')
dropdown.setValue(this.plugin.settings.ctrlKey ? 'ctrl' : 'alt')
dropdown.onChange(async (value) => {
this.plugin.settings.ctrlKey = value === 'ctrl';
this.plugin.settings.altKey = value === 'alt';
await this.plugin.saveSettings();
this.display();
});
});
}

View file

@ -1,4 +1,4 @@
.fn-whitespace-collapsing .nav-folder-title-content.has-folder-note {
.fn-whitespace-collapsing .nav-folder-title-content {
flex-grow: 1;
padding-bottom: 4px;
padding-top: 4px;
@ -11,7 +11,7 @@
text-underline-offset: 1px;
}
.fn-whitespace-collapsing .nav-folder-title:has(.has-folder-note) {
.fn-whitespace-collapsing .nav-folder-title {
padding-bottom: 0;
padding-top: 0;
}