import {useCommon} from "@/composables";
import {computed, ref} from "@vue/reactivity";
-import {inject} from "@vue/runtime-core";
+import {inject, nextTick} from "@vue/runtime-core";
import AreYouSure from "@/components/modals/AreYouSure";
import {FontAwesomeIcon} from "@fortawesome/vue-fontawesome";
+import {findNodeAtOffsetWithNullOffset} from "@/utils";
+import {emit, Events} from "@/eventbus";
export default {
name: "BookmarkButtons",
props: {
bookmark: {type: Object, required: true},
showStudyPadButtons: {type: Boolean, default: false},
+ documentId: {type: String, default: null},
},
emits: ["close-bookmark", "info-clicked"],
components: {AreYouSure, FontAwesomeIcon},
- setup(props, {emit}) {
+ setup(props, {emit: $emit}) {
const areYouSure = ref(null);
const bookmark = computed(() => props.bookmark);
@@ -102,14 +108,41 @@ export default {
async function removeBookmark() {
if(await areYouSure.value.areYouSure()) {
- emit("close-bookmark");
+ $emit("close-bookmark");
android.removeBookmark(bookmark.value.id);
}
}
+ async function adjustRange() {
+ const documentId = props.documentId;
+ const [startOrdinal, endOrdinal] = bookmark.value.ordinalRange;
+ const [startOff, endOff] = bookmark.value.offsetRange;
+ const firstElem = document.querySelector(`#doc-${documentId} #v-${startOrdinal}`);
+ const secondElem = document.querySelector(`#doc-${documentId} #v-${endOrdinal}`);
+ if (firstElem === null || secondElem === null) {
+ console.error("Element is not found!", documentId, startOrdinal, endOrdinal);
+ return;
+ }
+ const [first, startOff1] = findNodeAtOffsetWithNullOffset(firstElem, startOff);
+ const [second, endOff1] = findNodeAtOffsetWithNullOffset(secondElem, endOff);
+ emit(Events.CLOSE_MODALS);
+ await nextTick();
+
+ const range = new Range();
+ range.setStart(first, startOff1);
+ range.setEnd(second, endOff1);
+
+ const sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ //android.adjustRange();
+ console.log("clicking", firstElem, sel, range);
+ //firstElem.click();
+ }
+
return {
toggleWholeVerse, shareVerse, assignLabels, removeBookmark, areYouSure, labels, openStudyPad,
- ...useCommon()
+ adjustRange, ...useCommon()
}
}
}
diff --git a/app/bibleview-js/src/components/documents/BibleDocument.vue b/app/bibleview-js/src/components/documents/BibleDocument.vue
index 3cd5ea67f0..9222621af4 100644
--- a/app/bibleview-js/src/components/documents/BibleDocument.vue
+++ b/app/bibleview-js/src/components/documents/BibleDocument.vue
@@ -43,7 +43,7 @@ export default {
// eslint-disable-next-line no-unused-vars,vue/no-setup-props-destructure
const {id, bookInitials, bookmarks, ordinalRange, originalOrdinalRange, v11n} = props.document;
- provide("bibleDocumentInfo", {ordinalRange, originalOrdinalRange, v11n})
+ provide("bibleDocumentInfo", {id, ordinalRange, originalOrdinalRange, v11n})
const globalBookmarks = inject("globalBookmarks");
globalBookmarks.updateBookmarks(...bookmarks);
diff --git a/app/bibleview-js/src/components/modals/AmbiguousSelection.vue b/app/bibleview-js/src/components/modals/AmbiguousSelection.vue
index 0372aa53ea..4689bfbdc2 100644
--- a/app/bibleview-js/src/components/modals/AmbiguousSelection.vue
+++ b/app/bibleview-js/src/components/modals/AmbiguousSelection.vue
@@ -28,6 +28,7 @@
@@ -85,7 +86,7 @@ export default {
if(eventFunctions.length > 0) {
if(eventFunctions.length === 1) {
if(eventFunctions[0].options.bookmarkId) {
- emit(Events.BOOKMARK_CLICKED, eventFunctions[0].options.bookmarkId);
+ emit(Events.BOOKMARK_CLICKED, eventFunctions[0].options.bookmarkId, eventFunctions[0].options.documentId);
} else {
eventFunctions[0].callback();
}
diff --git a/app/bibleview-js/src/components/modals/AmbiguousSelectionBookmarkButton.vue b/app/bibleview-js/src/components/modals/AmbiguousSelectionBookmarkButton.vue
index bcebfff91a..807fc38526 100644
--- a/app/bibleview-js/src/components/modals/AmbiguousSelectionBookmarkButton.vue
+++ b/app/bibleview-js/src/components/modals/AmbiguousSelectionBookmarkButton.vue
@@ -24,6 +24,7 @@
@@ -45,6 +46,7 @@ export default {
name: "AmbiguousSelectionBookmarkButton",
props: {
bookmarkId: {required: true, type: Number},
+ documentId: {required: true, type: String},
},
components: {LabelList, BookmarkButtons},
setup(props, {emit: $emit}) {
@@ -71,17 +73,17 @@ export default {
function editNotes() {
$emit("selected");
- emit(Events.BOOKMARK_CLICKED, bookmark.value.id, {open: true});
+ emit(Events.BOOKMARK_CLICKED, bookmark.value.id, props.documentId, {open: true});
}
function openBookmark() {
$emit("selected");
- emit(Events.BOOKMARK_CLICKED, bookmark.value.id);
+ emit(Events.BOOKMARK_CLICKED, bookmark.value.id, props.documentId);
}
function bookmarkInfo() {
$emit("selected");
- emit(Events.BOOKMARK_CLICKED, bookmark.value.id, {openInfo: true});
+ emit(Events.BOOKMARK_CLICKED, bookmark.value.id, props.documentId, {openInfo: true});
}
return {
diff --git a/app/bibleview-js/src/components/modals/BookmarkModal.vue b/app/bibleview-js/src/components/modals/BookmarkModal.vue
index f2b7bb0bb0..e9f169390b 100644
--- a/app/bibleview-js/src/components/modals/BookmarkModal.vue
+++ b/app/bibleview-js/src/components/modals/BookmarkModal.vue
@@ -66,6 +66,7 @@