@@ -10,7 +10,7 @@ import ModalContainer from "./ModalContainer.svelte"
|
||||
import { eventBus, type ResultNote } from "src/globals"
|
||||
import { createNote, openNote } from "src/notes"
|
||||
import { getSuggestions, reindexNotes } from "src/search"
|
||||
import { loopIndex } from "src/utils"
|
||||
import { getCtrlKeyLabel, loopIndex } from "src/utils"
|
||||
import { OmnisearchInFileModal, type OmnisearchVaultModal } from "src/modals"
|
||||
import ResultItemVault from "./ResultItemVault.svelte"
|
||||
import { Query } from "src/query"
|
||||
@@ -176,7 +176,7 @@ async function scrollIntoView(): Promise<void> {
|
||||
<br />
|
||||
|
||||
<div class="prompt-instruction">
|
||||
<span class="prompt-instruction-command">ctrl ↵</span>
|
||||
<span class="prompt-instruction-command">{getCtrlKeyLabel()} ↵</span>
|
||||
<span>to open in a new pane</span>
|
||||
</div>
|
||||
<div class="prompt-instruction">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { App, Modal, TFile } from 'obsidian'
|
||||
import { App, Modal, TFile, Platform } from 'obsidian'
|
||||
import ModalVault from './components/ModalVault.svelte'
|
||||
import ModalInFile from './components/ModalInFile.svelte'
|
||||
import { eventBus, isInputComposition } from './globals'
|
||||
@@ -61,15 +61,10 @@ abstract class OmnisearchModal extends Modal {
|
||||
}
|
||||
|
||||
// #endregion Up/Down navigation
|
||||
|
||||
this.scope.register(['Ctrl'], 'Enter', e => {
|
||||
this.scope.register(['Mod'], 'Enter', e => {
|
||||
e.preventDefault()
|
||||
eventBus.emit('ctrl-enter') // Open in new pane
|
||||
})
|
||||
this.scope.register(['Meta'], 'Enter', e => {
|
||||
e.preventDefault()
|
||||
eventBus.emit('ctrl-enter') // Open in new pane (but on Mac)
|
||||
})
|
||||
|
||||
this.scope.register(['Alt'], 'Enter', e => {
|
||||
e.preventDefault()
|
||||
|
||||
13
src/notes.ts
13
src/notes.ts
@@ -62,23 +62,20 @@ export async function openNote(
|
||||
reg.exec(item.content)
|
||||
const offset = reg.lastIndex
|
||||
|
||||
// Check if the note is already open
|
||||
// const pane = MarkdownView.getPane(item.path)
|
||||
|
||||
// Check if the note is already open,
|
||||
// to avoid opening it twice if the first one is pinned
|
||||
let existing = false
|
||||
let alreadyOpenAndPinned = false
|
||||
app.workspace.iterateAllLeaves(leaf => {
|
||||
if (leaf.view instanceof MarkdownView) {
|
||||
if (leaf.getViewState().state?.file === item.path) {
|
||||
if (!newPane && leaf.getViewState().state?.file === item.path && leaf.getViewState()?.pinned) {
|
||||
app.workspace.setActiveLeaf(leaf, false, true)
|
||||
existing = true
|
||||
alreadyOpenAndPinned = true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (!existing) {
|
||||
// Open a new note
|
||||
if (!alreadyOpenAndPinned) {
|
||||
// Open the note normally
|
||||
await app.workspace.openLinkText(item.path, '', newPane)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CachedMetadata } from 'obsidian'
|
||||
import { Platform, type CachedMetadata } from 'obsidian'
|
||||
import {
|
||||
excerptAfter,
|
||||
excerptBefore,
|
||||
@@ -164,3 +164,7 @@ export function getTagsFromMetadata(metadata: CachedMetadata | null): string[] {
|
||||
export function removeDiacritics(str: string): string {
|
||||
return str.normalize('NFD').replace(/\p{Diacritic}/gu, '')
|
||||
}
|
||||
|
||||
export function getCtrlKeyLabel(): 'ctrl' | '⌘' {
|
||||
return Platform.isMacOS ? '⌘' : 'ctrl'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user