From 5049931fdd04a4b8e0d5e5778a53b8527404760e Mon Sep 17 00:00:00 2001 From: Benedictteo05 <75201951+Benedictteo05@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:03:53 +0800 Subject: [PATCH] fix querying multiple verse --- src/suggesetor/VerseEditorSuggester.ts | 4 +--- src/utils/reg.test.ts | 10 +++++----- src/utils/regs.ts | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/suggesetor/VerseEditorSuggester.ts b/src/suggesetor/VerseEditorSuggester.ts index 2ceabec..3b66539 100644 --- a/src/suggesetor/VerseEditorSuggester.ts +++ b/src/suggesetor/VerseEditorSuggester.ts @@ -55,13 +55,11 @@ export class VerseEditorSuggester extends EditorSuggest { const queryContent = currentContent.substring(2) const match = verseMatch(queryContent) - if (match) { - const vMatch = versionMatch(queryContent) if (vMatch) { - this.plugin.settings.bibleVersion = vMatch if (getBibleVersion(vMatch).key == vMatch) { + this.plugin.settings.bibleVersion = vMatch this.plugin.saveSettings() } } else { diff --git a/src/utils/reg.test.ts b/src/utils/reg.test.ts index 1c7db2a..2263826 100644 --- a/src/utils/reg.test.ts +++ b/src/utils/reg.test.ts @@ -76,7 +76,7 @@ describe('test modal reg matching in different languages', () => { }) test('should match version with only alphabets', () => { - const modal = '-niv2011' + const modal = '-esv' const reg = new RegExp(VERSION_REG) expect(reg.test(modal)).toBe(true) }) @@ -87,10 +87,10 @@ describe('test modal reg matching in different languages', () => { expect(reg.test(modal)).toBe(true) }) - test('should not match when there is hyphen', () => { - const modal = '-should-fail' - const reg = new RegExp(MODAL_REG) - expect(reg.test(modal)).toBe(false) + test('should match even when there is hyphen', () => { + const modal = '-oeb-cw' + const reg = new RegExp(VERSION_REG) + expect(reg.test(modal)).toBe(true) }) }) diff --git a/src/utils/regs.ts b/src/utils/regs.ts index 3ee42a5..93b6a7f 100644 --- a/src/utils/regs.ts +++ b/src/utils/regs.ts @@ -11,7 +11,7 @@ export const MODAL_REG = /([123])*\s*([\p{L}[\\\]^_`a-zA-Z]{2,100}|\p{Script=Han export const BOOK_REG = /([123])*\s*([\p{L}[\\\]^_`a-zA-Z]{2,100}|\p{Script=Han}{1,})/isu -export const VERSION_REG = /(-[a-zA-Z0-9]+)$/isu +export const VERSION_REG = /-[a-zA-Z][a-zA-Z0-9-]*$/isu // export const BOOK_REG = /[123]*\s*[A-Z\[\\\]^_`a-z]{2,}/