From ece9b16014565dbdffdfeee9fa5c0fbd11542d7c Mon Sep 17 00:00:00 2001 From: Lost Paul <70213368+LostPaul@users.noreply.github.com> Date: Tue, 28 Mar 2023 10:58:36 +0200 Subject: [PATCH] MacOS cmd + click support --- src/main.ts | 9 +++++---- src/settings.ts | 23 +++++++++++++---------- styles.css | 4 ++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main.ts b/src/main.ts index 9d02d8c..512ac0d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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) => { diff --git a/src/settings.ts b/src/settings.ts index c9e4f58..3da885e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -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(); + }); }); } diff --git a/styles.css b/styles.css index e2cb8c6..8c22fef 100644 --- a/styles.css +++ b/styles.css @@ -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; }