Fixed #116, overall safer code in ModalVault

This commit is contained in:
Simon Cambier
2022-10-24 22:44:43 +02:00
parent d62fff6ce4
commit 6f7d454470
2 changed files with 18 additions and 11 deletions

View File

@@ -17,8 +17,8 @@
export let modal: OmnisearchVaultModal
let selectedIndex = 0
let historySearchIndex = 0
let searchQuery: string
let previousQuery: string
let searchQuery: string | undefined
let previousQuery: string | undefined
let resultNotes: ResultNote[] = []
let query: Query
@@ -100,8 +100,10 @@
}
function saveCurrentQuery() {
if (searchQuery) {
cacheManager.addToSearchHistory(searchQuery)
}
}
function openSearchResult(note: ResultNote, newPane = false) {
saveCurrentQuery()
@@ -115,6 +117,7 @@
async function createNoteAndCloseModal(opt?: {
newLeaf: boolean
}): Promise<void> {
if (searchQuery) {
try {
await createNote(searchQuery, opt?.newLeaf)
} catch (e) {
@@ -123,6 +126,7 @@
}
modal.close()
}
}
function insertLink(): void {
if (!selectedNote) return
@@ -154,11 +158,14 @@
}
function switchToInFileModal(): void {
if (selectedNote.path.endsWith('.pdf')) {
// Do nothing if the selectedNote is a PDF
if (selectedNote?.path.endsWith('.pdf')) {
return
}
saveCurrentQuery()
modal.close()
if (selectedNote) {
// Open in-file modal for selected search result
const file = app.vault.getAbstractFileByPath(selectedNote.path)

View File

@@ -192,7 +192,7 @@ export function getPlaintextExtensions(): string[] {
export function getExtension(path: string): string {
const split = path.split('.')
return split[split.length - 1]
return split[split.length - 1] ?? ''
}
export function makeMD5(data: BinaryLike): string {