Skip to content

Commit

Permalink
Use (also) JSword reference parsing (related: #2845)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomas2 committed Sep 14, 2023
1 parent a55e97d commit 17a5a38
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/bibleview-js/src/components/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ const bibleLink = {
while (parsed === "" && text !== null) {
text = await inputText.value!.inputText(text, error);
if (text !== null) {
parsed = parse(text)
parsed = await android.parseRef(text)
if(parsed === "") {
parsed = parse(text)
}
if (parsed === "") {
error = strings.invalidReference;
} else {
Expand Down
7 changes: 7 additions & 0 deletions app/bibleview-js/src/composables/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type BibleJavascriptInterface = {
requestMoreToBeginning: AsyncFunc,
requestMoreToEnd: AsyncFunc,
refChooserDialog: AsyncFunc,
parseRef: (callId: number, s: String) => void,
saveBookmarkNote: (bookmarkId: IdType, note: Nullable<string>) => void,
saveGenericBookmarkNote: (bookmarkId: IdType, note: Nullable<string>) => void,
removeBookmark: (bookmarkId: IdType) => void,
Expand Down Expand Up @@ -402,6 +403,11 @@ export function useAndroid({bookmarks}: { bookmarks: Ref<BaseBookmark[]> }, conf
window.android.openDownloads();
}

async function parseRef(s: string): Promise<string> {
const result = await deferredCall((callId) => window.android.parseRef(callId, s))
return result ?? ""
}

function updateOrderNumber(
labelId: IdType,
bookmarks: StudyPadBibleBookmarkItem[],
Expand Down Expand Up @@ -536,6 +542,7 @@ export function useAndroid({bookmarks}: { bookmarks: Ref<BaseBookmark[]> }, conf
speakGeneric,
helpDialog,
onKeyDown,
parseRef,
}

if (config.developmentMode) return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ class BibleJavascriptInterface(
bibleView.requestMoreToEnd(callId)
}

@JavascriptInterface
fun parseRef(callId: Long, s: String) {
Log.i(TAG, "Request more text at end")
bibleView.parseRef(callId, s)
}

@JavascriptInterface
fun refChooserDialog(callId: Long) {
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import net.bible.android.database.IdType
import net.bible.android.database.bookmarks.BookmarkEntities
import net.bible.android.database.bookmarks.KJVA
import net.bible.android.database.json
import net.bible.android.misc.wrapString
import net.bible.android.view.activity.base.DocumentView
import net.bible.android.view.activity.base.IntentHelper
import net.bible.android.view.activity.base.SharedActivityState
Expand Down Expand Up @@ -1925,6 +1926,11 @@ class BibleView(val mainBibleActivity: MainBibleActivity,
super.onFocusChanged(focused, direction, previouslyFocusedRect)
}

fun parseRef(callId: Long, s: String) {
val ref = wrapString(linkControl.resolveRef(s, (firstDocument as? BibleDocument)?.swordBook)?.osisRef)
executeJavascriptOnUiThread("bibleView.response($callId, $ref);")
}

var onDestroy: (() -> Unit)? = null

private val TAG get() = "BibleView[${windowRef.get()?.displayId}]"
Expand Down

0 comments on commit 17a5a38

Please sign in to comment.