From 027c9e3bc9166289e192379ed83265463dbaa00b Mon Sep 17 00:00:00 2001 From: Ian Fisher Date: Fri, 19 May 2023 03:53:31 -0400 Subject: [PATCH] Add setting to open/create files in new pane by default (#241) * Manifest 1.14.1-beta.1 * 1.14.1-beta.2 manifest * Add setting to open/create files in new pane by default * Fix typo with key labels * Address review comments --------- Co-authored-by: Simon Cambier --- manifest-beta.json | 2 +- src/components/ModalVault.svelte | 23 +++++++++++++++++++---- src/components/modals.ts | 26 ++++++++++++++++++++++---- src/settings.ts | 14 ++++++++++++++ versions.json | 4 +++- 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/manifest-beta.json b/manifest-beta.json index 6f67936..7ea5551 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "omnisearch", "name": "Omnisearch", - "version": "1.14.0", + "version": "1.14.1-beta.2", "minAppVersion": "1.0.0", "description": "A search engine that just works", "author": "Simon Cambier", diff --git a/src/components/ModalVault.svelte b/src/components/ModalVault.svelte index ebee3fa..b35d964 100644 --- a/src/components/ModalVault.svelte +++ b/src/components/ModalVault.svelte @@ -39,9 +39,24 @@ let indexingStepDesc = '' let searching = true let refInput: InputSearch | undefined + let openInNewPaneKey: string + let openInCurrentPaneKey: string + let createInNewPaneKey: string + let createInCurrentPaneKey: string $: selectedNote = resultNotes[selectedIndex] $: searchQuery = searchQuery ?? previousQuery + $: if (settings.openInNewPane) { + openInNewPaneKey = '↵' + openInCurrentPaneKey = getCtrlKeyLabel() + ' ↵' + createInNewPaneKey = 'shift ↵' + createInCurrentPaneKey = 'ctrl shift ↵' + } else { + openInNewPaneKey = getCtrlKeyLabel() + ' ↵' + openInCurrentPaneKey = '↵' + createInNewPaneKey = 'ctrl shift ↵' + createInCurrentPaneKey = 'shift ↵' + } $: if (searchQuery) { searching = true updateResults().then(() => { @@ -309,7 +324,7 @@ to cycle history
- to open + {openInCurrentPaneKey}to open
tab @@ -317,15 +332,15 @@
- {getCtrlKeyLabel()} ↵ + {openInNewPaneKey} to open in a new pane
- shift ↵ + {createInCurrentPaneKey} to create
- ctrl shift ↵ + {createInNewPaneKey} to create in a new pane
diff --git a/src/components/modals.ts b/src/components/modals.ts index 7b16729..17478ff 100644 --- a/src/components/modals.ts +++ b/src/components/modals.ts @@ -1,7 +1,9 @@ import { App, Modal, TFile } from 'obsidian' +import type { Modifier } from 'obsidian' import ModalVault from './ModalVault.svelte' import ModalInFile from './ModalInFile.svelte' import { eventBus, EventNames, isInputComposition } from '../globals' +import { settings } from '../settings' abstract class OmnisearchModal extends Modal { protected constructor(app: App) { @@ -61,8 +63,24 @@ abstract class OmnisearchModal extends Modal { // #endregion Up/Down navigation + let openInCurrentPaneKey: Modifier[] + let openInNewPaneKey: Modifier[] + let createInCurrentPaneKey: Modifier[] + let createInNewPaneKey: Modifier[] + if (settings.openInNewPane) { + openInCurrentPaneKey = ['Mod'] + openInNewPaneKey = [] + createInCurrentPaneKey = ['Ctrl', 'Shift'] + createInNewPaneKey = ['Shift'] + } else { + openInCurrentPaneKey = [] + openInNewPaneKey = ['Mod'] + createInCurrentPaneKey = ['Shift'] + createInNewPaneKey = ['Ctrl', 'Shift'] + } + // Open in new pane - this.scope.register(['Mod'], 'Enter', e => { + this.scope.register(openInNewPaneKey, 'Enter', e => { e.preventDefault() eventBus.emit('open-in-new-pane') }) @@ -74,17 +92,17 @@ abstract class OmnisearchModal extends Modal { }) // Create a new note - this.scope.register(['Shift'], 'Enter', e => { + this.scope.register(createInCurrentPaneKey, 'Enter', e => { e.preventDefault() eventBus.emit('create-note') }) - this.scope.register(['Ctrl', 'Shift'], 'Enter', e => { + this.scope.register(createInNewPaneKey, 'Enter', e => { e.preventDefault() eventBus.emit('create-note', { newLeaf: true }) }) // Open in current pane - this.scope.register([], 'Enter', e => { + this.scope.register(openInCurrentPaneKey, 'Enter', e => { if (!isInputComposition()) { // Check if the user is still typing e.preventDefault() diff --git a/src/settings.ts b/src/settings.ts index 0d2548f..32d2485 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -47,6 +47,7 @@ export interface OmnisearchSettings extends WeightingSettings { simpleSearch: boolean highlight: boolean splitCamelCase: boolean + openInNewPane: boolean verboseLogging: boolean } @@ -246,6 +247,18 @@ export class SettingsTab extends PluginSettingTab { }) ) + new Setting(containerEl) + .setName('Open in new pane') + .setDesc( + 'Open and create files in a new pane instead of the current pane.' + ) + .addToggle(toggle => + toggle.setValue(settings.openInNewPane).onChange(async v => { + settings.openInNewPane = v + await saveSettings(this.plugin) + }) + ) + //#endregion Behavior //#region User Interface @@ -445,6 +458,7 @@ export const DEFAULT_SETTINGS: OmnisearchSettings = { PDFIndexing: false, imagesIndexing: false, splitCamelCase: false, + openInNewPane: false, ribbonIcon: true, showExcerpt: true, diff --git a/versions.json b/versions.json index 199be64..20bcba2 100644 --- a/versions.json +++ b/versions.json @@ -105,5 +105,7 @@ "1.13.0-beta.2": "1.0.0", "1.13.0": "1.0.0", "1.14.0-beta.1": "1.0.0", - "1.14.0": "1.0.0" + "1.14.0": "1.0.0", + "1.14.1-beta.1": "1.0.0", + "1.14.1-beta.2": "1.0.0" } \ No newline at end of file