Skip to content

Commit 2506e28

Browse files
qirong77linqirong
andauthored
Fix the unexpected console error that occurs when updating the shadow dom selection in monaco-editor (microsoft#215780)
* fix monaco inlinesuggest toolbar loses css color problem * Fix the unexpected console error that occurs when updating the shadow dom selection in monaco-editor --------- Co-authored-by: linqirong <[email protected]>
1 parent da6f630 commit 2506e28

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/vs/editor/browser/controller/mouseTarget.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,14 +1110,14 @@ function shadowCaretRangeFromPoint(shadowRoot: ShadowRoot, x: number, y: number)
11101110
const range = document.createRange();
11111111

11121112
// Get the element under the point
1113-
let el: Element | null = (<any>shadowRoot).elementFromPoint(x, y);
1114-
1115-
if (el !== null) {
1113+
let el: HTMLElement | null = (<any>shadowRoot).elementFromPoint(x, y);
1114+
// When el is not null, it may be div.monaco-mouse-cursor-text Element, which has not childNodes, we don't need to handle it.
1115+
if (el?.hasChildNodes()) {
11161116
// Get the last child of the element until its firstChild is a text node
11171117
// This assumes that the pointer is on the right of the line, out of the tokens
11181118
// and that we want to get the offset of the last token of the line
11191119
while (el && el.firstChild && el.firstChild.nodeType !== el.firstChild.TEXT_NODE && el.lastChild && el.lastChild.firstChild) {
1120-
el = <Element>el.lastChild;
1120+
el = <HTMLElement>el.lastChild;
11211121
}
11221122

11231123
// Grab its rect
@@ -1134,7 +1134,7 @@ function shadowCaretRangeFromPoint(shadowRoot: ShadowRoot, x: number, y: number)
11341134
const font = `${fontStyle} ${fontVariant} ${fontWeight} ${fontSize}/${lineHeight} ${fontFamily}`;
11351135

11361136
// And also its txt content
1137-
const text = (el as any).innerText;
1137+
const text = el.innerText;
11381138

11391139
// Position the pixel cursor at the left of the element
11401140
let pixelCursor = rect.left;

0 commit comments

Comments
 (0)