Fixed #116, overall safer code in ModalVault
This commit is contained in:
@@ -17,8 +17,8 @@
|
|||||||
export let modal: OmnisearchVaultModal
|
export let modal: OmnisearchVaultModal
|
||||||
let selectedIndex = 0
|
let selectedIndex = 0
|
||||||
let historySearchIndex = 0
|
let historySearchIndex = 0
|
||||||
let searchQuery: string
|
let searchQuery: string | undefined
|
||||||
let previousQuery: string
|
let previousQuery: string | undefined
|
||||||
let resultNotes: ResultNote[] = []
|
let resultNotes: ResultNote[] = []
|
||||||
let query: Query
|
let query: Query
|
||||||
|
|
||||||
@@ -100,7 +100,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function saveCurrentQuery() {
|
function saveCurrentQuery() {
|
||||||
cacheManager.addToSearchHistory(searchQuery)
|
if (searchQuery) {
|
||||||
|
cacheManager.addToSearchHistory(searchQuery)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openSearchResult(note: ResultNote, newPane = false) {
|
function openSearchResult(note: ResultNote, newPane = false) {
|
||||||
@@ -115,13 +117,15 @@
|
|||||||
async function createNoteAndCloseModal(opt?: {
|
async function createNoteAndCloseModal(opt?: {
|
||||||
newLeaf: boolean
|
newLeaf: boolean
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
try {
|
if (searchQuery) {
|
||||||
await createNote(searchQuery, opt?.newLeaf)
|
try {
|
||||||
} catch (e) {
|
await createNote(searchQuery, opt?.newLeaf)
|
||||||
new Notice((e as Error).message)
|
} catch (e) {
|
||||||
return
|
new Notice((e as Error).message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
modal.close()
|
||||||
}
|
}
|
||||||
modal.close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertLink(): void {
|
function insertLink(): void {
|
||||||
@@ -154,11 +158,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function switchToInFileModal(): void {
|
function switchToInFileModal(): void {
|
||||||
if (selectedNote.path.endsWith('.pdf')) {
|
// Do nothing if the selectedNote is a PDF
|
||||||
|
if (selectedNote?.path.endsWith('.pdf')) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
saveCurrentQuery()
|
saveCurrentQuery()
|
||||||
modal.close()
|
modal.close()
|
||||||
|
|
||||||
if (selectedNote) {
|
if (selectedNote) {
|
||||||
// Open in-file modal for selected search result
|
// Open in-file modal for selected search result
|
||||||
const file = app.vault.getAbstractFileByPath(selectedNote.path)
|
const file = app.vault.getAbstractFileByPath(selectedNote.path)
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ export function getPlaintextExtensions(): string[] {
|
|||||||
|
|
||||||
export function getExtension(path: string): string {
|
export function getExtension(path: string): string {
|
||||||
const split = path.split('.')
|
const split = path.split('.')
|
||||||
return split[split.length - 1]
|
return split[split.length - 1] ?? ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeMD5(data: BinaryLike): string {
|
export function makeMD5(data: BinaryLike): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user