From 5bfb3699d0410c6ae9cc228907b57a7f41b08159 Mon Sep 17 00:00:00 2001 From: tim-hub Date: Sat, 14 Dec 2024 12:48:25 +1300 Subject: [PATCH] make it work again --- src/suggesetor/VerseEditorSuggester.ts | 16 +++++++++------- src/utils/getSuggestionsFromQuery.ts | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/suggesetor/VerseEditorSuggester.ts b/src/suggesetor/VerseEditorSuggester.ts index 9de6863..12425a5 100644 --- a/src/suggesetor/VerseEditorSuggester.ts +++ b/src/suggesetor/VerseEditorSuggester.ts @@ -68,18 +68,20 @@ export class VerseEditorSuggester extends EditorSuggest { const { bookVerseQuery, translationQuery } = this.getBookVerseAndTranslation(queryContent) const verseMatchResult = verseMatch(bookVerseQuery) + const versionSelectionMatchResult = versionSelectionMatch(translationQuery) + if (verseMatchResult && verseMatchResult.length > 0) { - const versionSelectionMatchResult = versionSelectionMatch(translationQuery) - if (!translationQuery || !versionSelectionMatchResult || getBibleVersion(versionSelectionMatchResult).key == versionSelectionMatchResult ) { + if (versionSelectionMatchResult && getBibleVersion(versionSelectionMatchResult).key == versionSelectionMatchResult ) { + console.log(`set version : ${versionSelectionMatchResult}`) + this.plugin.settings.bibleVersion = versionSelectionMatchResult // pick a version + this.plugin.saveSettings() //todo this is an async function, so it may not be saved before the getSuggestions is called + } else { + // revert back to default version if (this.settings.bibleVersion != this.settings.defaultBibleVersion) { this.settings.bibleVersion = this.settings.defaultBibleVersion // reset to default console.log(`defaultBibleVersion : ${this.settings.defaultBibleVersion}`) this.plugin.saveSettings() } - } else { - console.log(`set version : ${versionSelectionMatchResult}`) - this.plugin.settings.bibleVersion = versionSelectionMatchResult // pick a version - this.plugin.saveSettings() //todo this is an async function, so it may not be saved before the getSuggestions is called } console.debug('trigger on', queryContent) @@ -94,7 +96,7 @@ export class VerseEditorSuggester extends EditorSuggest { line: cursor.line, ch: queryContent.lastIndexOf(verseMatchResult), }, - query: queryContent, + query: `${verseMatchResult}@${versionSelectionMatchResult}`, } } return null diff --git a/src/utils/getSuggestionsFromQuery.ts b/src/utils/getSuggestionsFromQuery.ts index d420d11..44f515a 100644 --- a/src/utils/getSuggestionsFromQuery.ts +++ b/src/utils/getSuggestionsFromQuery.ts @@ -14,7 +14,7 @@ export const getSuggestionsFromQuery = async ( settings: BibleReferencePluginSettings, translation?: string ): Promise => { - console.debug('get suggestion for query ', queryWithoutPrefix.toLowerCase()) + console.debug('get suggestion for query ', queryWithoutPrefix.toLowerCase(), translation, settings.bibleVersion, settings.defaultBibleVersion) const bookNameMatchingResults = queryWithoutPrefix.match(BOOK_REG) const rawBookName = bookNameMatchingResults?.length