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 <simon.cambier@protonmail.com>
This commit is contained in:
Ian Fisher
2023-05-19 03:53:31 -04:00
committed by GitHub
parent b5c1d31e85
commit 027c9e3bc9
5 changed files with 59 additions and 10 deletions

View File

@@ -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 @@
<span>to cycle history</span>
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command"></span><span>to open</span>
<span class="prompt-instruction-command">{openInCurrentPaneKey}</span><span>to open</span>
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">tab</span>
@@ -317,15 +332,15 @@
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">{getCtrlKeyLabel()}</span>
<span class="prompt-instruction-command">{openInNewPaneKey}</span>
<span>to open in a new pane</span>
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">shift ↵</span>
<span class="prompt-instruction-command">{createInCurrentPaneKey}</span>
<span>to create</span>
</div>
<div class="prompt-instruction">
<span class="prompt-instruction-command">ctrl shift ↵</span>
<span class="prompt-instruction-command">{createInNewPaneKey}</span>
<span>to create in a new pane</span>
</div>

View File

@@ -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()

View File

@@ -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,