Fix equals function on TextSourceRange when imposter elements are used
This commit is contained in:
parent
54a48a7a9b
commit
1f3ff6fad0
@ -148,7 +148,7 @@ class SettingsPopupPreview {
|
|||||||
|
|
||||||
const range = document.createRange();
|
const range = document.createRange();
|
||||||
range.selectNode(textNode);
|
range.selectNode(textNode);
|
||||||
const source = new TextSourceRange(range, range.toString(), null);
|
const source = new TextSourceRange(range, range.toString(), null, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.frontend.onSearchSource(source, 'script');
|
await this.frontend.onSearchSource(source, 'script');
|
||||||
|
@ -110,6 +110,7 @@ function docRangeFromPoint(x, y, deepDomScan) {
|
|||||||
const elements = docElementsFromPoint(x, y, deepDomScan);
|
const elements = docElementsFromPoint(x, y, deepDomScan);
|
||||||
let imposter = null;
|
let imposter = null;
|
||||||
let imposterContainer = null;
|
let imposterContainer = null;
|
||||||
|
let imposterSourceElement = null;
|
||||||
if (elements.length > 0) {
|
if (elements.length > 0) {
|
||||||
const element = elements[0];
|
const element = elements[0];
|
||||||
switch (element.nodeName.toUpperCase()) {
|
switch (element.nodeName.toUpperCase()) {
|
||||||
@ -117,9 +118,11 @@ function docRangeFromPoint(x, y, deepDomScan) {
|
|||||||
case 'BUTTON':
|
case 'BUTTON':
|
||||||
return new TextSourceElement(element);
|
return new TextSourceElement(element);
|
||||||
case 'INPUT':
|
case 'INPUT':
|
||||||
|
imposterSourceElement = element;
|
||||||
[imposter, imposterContainer] = docImposterCreate(element, false);
|
[imposter, imposterContainer] = docImposterCreate(element, false);
|
||||||
break;
|
break;
|
||||||
case 'TEXTAREA':
|
case 'TEXTAREA':
|
||||||
|
imposterSourceElement = element;
|
||||||
[imposter, imposterContainer] = docImposterCreate(element, true);
|
[imposter, imposterContainer] = docImposterCreate(element, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -131,7 +134,7 @@ function docRangeFromPoint(x, y, deepDomScan) {
|
|||||||
docSetImposterStyle(imposterContainer.style, 'z-index', '-2147483646');
|
docSetImposterStyle(imposterContainer.style, 'z-index', '-2147483646');
|
||||||
docSetImposterStyle(imposter.style, 'pointer-events', 'none');
|
docSetImposterStyle(imposter.style, 'pointer-events', 'none');
|
||||||
}
|
}
|
||||||
return new TextSourceRange(range, '', imposterContainer);
|
return new TextSourceRange(range, '', imposterContainer, imposterSourceElement);
|
||||||
} else {
|
} else {
|
||||||
if (imposterContainer !== null) {
|
if (imposterContainer !== null) {
|
||||||
imposterContainer.parentNode.removeChild(imposterContainer);
|
imposterContainer.parentNode.removeChild(imposterContainer);
|
||||||
|
@ -25,14 +25,16 @@ const IGNORE_TEXT_PATTERN = /\u200c/;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
class TextSourceRange {
|
class TextSourceRange {
|
||||||
constructor(range, content, imposterContainer) {
|
constructor(range, content, imposterContainer, imposterSourceElement) {
|
||||||
this.range = range;
|
this.range = range;
|
||||||
|
this.rangeStartOffset = range.startOffset;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
this.imposterContainer = imposterContainer;
|
this.imposterContainer = imposterContainer;
|
||||||
|
this.imposterSourceElement = imposterSourceElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
clone() {
|
clone() {
|
||||||
return new TextSourceRange(this.range.cloneRange(), this.content, this.imposterContainer);
|
return new TextSourceRange(this.range.cloneRange(), this.content, this.imposterContainer, this.imposterSourceElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
@ -55,6 +57,7 @@ class TextSourceRange {
|
|||||||
setStartOffset(length) {
|
setStartOffset(length) {
|
||||||
const state = TextSourceRange.seekBackward(this.range.startContainer, this.range.startOffset, length);
|
const state = TextSourceRange.seekBackward(this.range.startContainer, this.range.startOffset, length);
|
||||||
this.range.setStart(state.node, state.offset);
|
this.range.setStart(state.node, state.offset);
|
||||||
|
this.rangeStartOffset = this.range.startOffset;
|
||||||
this.content = state.content;
|
this.content = state.content;
|
||||||
return length - state.remainder;
|
return length - state.remainder;
|
||||||
}
|
}
|
||||||
@ -79,7 +82,17 @@ class TextSourceRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
equals(other) {
|
equals(other) {
|
||||||
return other && other.range && other.range.compareBoundaryPoints(Range.START_TO_START, this.range) === 0;
|
if (other === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.imposterSourceElement !== null) {
|
||||||
|
return (
|
||||||
|
this.imposterSourceElement === other.imposterSourceElement &&
|
||||||
|
this.rangeStartOffset === other.rangeStartOffset
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return this.range.compareBoundaryPoints(Range.START_TO_START, other.range) === 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static shouldEnter(node) {
|
static shouldEnter(node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user