#7925: added cursor position management during a search with the carvet mode
This commit is contained in:
parent
d6f63d0e4b
commit
935aed5fb3
@ -103,7 +103,7 @@ const defaultOptions = {
|
|||||||
},
|
},
|
||||||
supportsCaretBrowsingMode: {
|
supportsCaretBrowsingMode: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: true,
|
||||||
kind: OptionKind.BROWSER,
|
kind: OptionKind.BROWSER,
|
||||||
},
|
},
|
||||||
supportsDocumentFonts: {
|
supportsDocumentFonts: {
|
||||||
|
|||||||
@ -182,16 +182,47 @@ class PDFFindBar {
|
|||||||
this.findField.focus();
|
this.findField.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
async close() {
|
||||||
if (!this.opened) {
|
if (!this.opened) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ele = document.querySelector(".highlight");
|
||||||
|
if (ele) {
|
||||||
|
ele.parentElement.setAttribute("id", "find-element");
|
||||||
|
}
|
||||||
|
const idxFindElement = ele
|
||||||
|
? ele.parentNode.innerHTML.indexOf(ele.outerHTML)
|
||||||
|
: null;
|
||||||
|
|
||||||
this.#resizeObserver.disconnect();
|
this.#resizeObserver.disconnect();
|
||||||
|
|
||||||
this.opened = false;
|
this.opened = false;
|
||||||
toggleExpandedBtn(this.toggleButton, false, this.bar);
|
toggleExpandedBtn(this.toggleButton, false, this.bar);
|
||||||
|
|
||||||
this.eventBus.dispatch("findbarclose", { source: this });
|
await this.eventBus.dispatch("findbarclose", { source: this });
|
||||||
|
|
||||||
|
// apply the cursor position for the caret mode
|
||||||
|
if (ele) {
|
||||||
|
const range = document.createRange();
|
||||||
|
const selection = document.getSelection();
|
||||||
|
|
||||||
|
const findElement = document.getElementById("find-element");
|
||||||
|
const walker = document.createTreeWalker(
|
||||||
|
findElement,
|
||||||
|
NodeFilter.SHOW_TEXT
|
||||||
|
);
|
||||||
|
const findElementChild = walker.firstChild();
|
||||||
|
|
||||||
|
if (findElementChild) {
|
||||||
|
range.setStart(findElementChild, idxFindElement);
|
||||||
|
range.setEnd(findElementChild, idxFindElement);
|
||||||
|
range.collapse(true);
|
||||||
|
selection.removeAllRanges();
|
||||||
|
selection.addRange(range);
|
||||||
|
findElement.removeAttribute("id");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user