Fixes microsoft/monaco-editor#2175: Improve hit testing code on FF

This commit is contained in:
Alexandru Dima 2021-01-28 22:20:30 +01:00
parent 9d9aebd2e6
commit 9934dea688
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0

View file

@ -940,12 +940,16 @@ export class MouseTargetFactory {
}
}
// For inline decorations, Gecko returns the `<span>` of the line and the offset is the `<span>` with the inline decoration
// For inline decorations, Gecko sometimes returns the `<span>` of the line and the offset is the `<span>` with the inline decoration
// Some other times, it returns the `<span>` with the inline decoration
if (hitResult.offsetNode.nodeType === hitResult.offsetNode.ELEMENT_NODE) {
const parent1 = hitResult.offsetNode.parentNode; // expected to be the view line div
const parent1 = hitResult.offsetNode.parentNode;
const parent1ClassName = parent1 && parent1.nodeType === parent1.ELEMENT_NODE ? (<HTMLElement>parent1).className : null;
const parent2 = parent1 ? parent1.parentNode : null;
const parent2ClassName = parent2 && parent2.nodeType === parent2.ELEMENT_NODE ? (<HTMLElement>parent2).className : null;
if (parent1ClassName === ViewLine.CLASS_NAME) {
// it returned the `<span>` of the line and the offset is the `<span>` with the inline decoration
const tokenSpan = hitResult.offsetNode.childNodes[Math.min(hitResult.offset, hitResult.offsetNode.childNodes.length - 1)];
if (tokenSpan) {
const p = ctx.getPositionFromDOMInfo(<HTMLElement>tokenSpan, 0);
@ -954,6 +958,13 @@ export class MouseTargetFactory {
hitTarget: null
};
}
} else if (parent2ClassName === ViewLine.CLASS_NAME) {
// it returned the `<span>` with the inline decoration
const p = ctx.getPositionFromDOMInfo(<HTMLElement>hitResult.offsetNode, 0);
return {
position: p,
hitTarget: null
};
}
}