diff --git a/src/ui/actions.ts b/src/ui/actions.ts index bb05629..9a3cbca 100644 --- a/src/ui/actions.ts +++ b/src/ui/actions.ts @@ -6,12 +6,14 @@ import EventCache from "src/core/EventCache"; * @param cache * @param param1 App * @param id event ID + * @param openInNewTab whether to open in new tab or not * @returns */ export async function openFileForEvent( cache: EventCache, { workspace, vault }: { workspace: Workspace; vault: Vault }, - id: string + id: string, + openInNewTab: boolean ) { const details = cache.getInfoForEditableEvent(id); if (!details) { @@ -28,7 +30,7 @@ export async function openFileForEvent( if (!leaf) { return; } - if (leaf.getViewState().pinned) { + if (leaf.getViewState().pinned || openInNewTab) { leaf = workspace.getLeaf("tab"); } await leaf.openFile(file); diff --git a/src/ui/settings.ts b/src/ui/settings.ts index da48222..22112b1 100644 --- a/src/ui/settings.ts +++ b/src/ui/settings.ts @@ -26,7 +26,9 @@ export interface FullCalendarSettings { mobile: string; }; timeFormat24h: boolean; - clickToCreateEventFromMonthView: boolean; + clickToCreateEventFromMonthView?: boolean; + alwaysOpenInNewTab?: boolean; + ctrlClickToOpenFile?: boolean; } export const DEFAULT_SETTINGS: FullCalendarSettings = { @@ -39,6 +41,8 @@ export const DEFAULT_SETTINGS: FullCalendarSettings = { }, timeFormat24h: false, clickToCreateEventFromMonthView: true, + alwaysOpenInNewTab: false, + ctrlClickToOpenFile: true, }; const WEEKDAYS = [ @@ -238,7 +242,7 @@ export class FullCalendarSettingTab extends PluginSettingTab { .setDesc("Switch off to open day view on click instead.") .addToggle((toggle) => { toggle.setValue( - this.plugin.settings.clickToCreateEventFromMonthView + this.plugin.settings.clickToCreateEventFromMonthView ?? true ); toggle.onChange(async (val) => { this.plugin.settings.clickToCreateEventFromMonthView = val; @@ -246,6 +250,38 @@ export class FullCalendarSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName("Always open events in a new tab") + .setDesc( + "Switch off to only open events in a new tab when the current tab is pinned." + ) + .addToggle((toggle) => { + toggle.setValue( + this.plugin.settings.alwaysOpenInNewTab ?? false + ); + toggle.onChange(async (val) => { + this.plugin.settings.alwaysOpenInNewTab = val; + await this.plugin.saveSettings(); + }); + }); + + new Setting(containerEl) + .setName( + "Click opens the edit dialog (ctrl-click to open event note)" + ) + .setDesc( + "Switch off to have click open note (ctrl-click for edit modal)." + ) + .addToggle((toggle) => { + toggle.setValue( + this.plugin.settings.ctrlClickToOpenFile ?? true + ); + toggle.onChange(async (val) => { + this.plugin.settings.ctrlClickToOpenFile = val; + await this.plugin.saveSettings(); + }); + }); + containerEl.createEl("h2", { text: "Manage Calendars" }); addCalendarButton( this.app, diff --git a/src/ui/view.ts b/src/ui/view.ts index 8a70ee7..b880132 100644 --- a/src/ui/view.ts +++ b/src/ui/view.ts @@ -126,14 +126,18 @@ export class CalendarView extends ItemView { forceNarrow: this.inSidebar, eventClick: async (info) => { try { - if ( + const hasModifierKey = info.jsEvent.getModifierState("Control") || - info.jsEvent.getModifierState("Meta") - ) { + info.jsEvent.getModifierState("Meta"); + const shouldOpenFile = + hasModifierKey && + this.plugin.settings.ctrlClickToOpenFile; + if (shouldOpenFile) { await openFileForEvent( this.plugin.cache, this.app, - info.event.id + info.event.id, + this.plugin.settings ); } else { launchEditModal(this.plugin, info.event.id);