Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] colorizeElement method doesn't color the whole text if domNode has more than one #text child #4571

Open
2 tasks done
juanbomfim22 opened this issue Jun 19, 2024 · 0 comments

Comments

@juanbomfim22
Copy link

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

No response

Monaco Editor Playground Code

No response

Reproduction Steps

It can be reproduced whenever appending one or more text nodes with document.createTextNode to a givendomNode. Tested with the latest monaco's version.

Here's a reproducible fiddle: https://jsfiddle.net/xw5zc4Lo/.

Actual (Problematic) Behavior

If you create an element with at least two #text, monaco.editor.colorizeElement will just colorize the firstChild's nodeValue as seen in the colorizeElement implementation.

public static colorizeElement(themeService: IStandaloneThemeService, languageService: ILanguageService, domNode: HTMLElement, options: IColorizerElementOptions): Promise<void> {
    // ...
    const text = domNode.firstChild ? domNode.firstChild.nodeValue : '';
    // ...
    return this.colorize(languageService, text || '', languageId, options).then(render, (err) => console.error(err));
}

A simple example is shown below. There's an initial text node and another one that is appended. After it happens, the colorize method is triggered, but it strips the newly added text node and just colorizes the first one.
SuiTmEZ

Expected Behavior

It is expected that the attribute wholeText is used to color all text present in the node instead of nodeValue, because it will concatenate any following #text present after the firstChild. As per MDN,

The read-only wholeText property of the Text interface returns the full text of all Text nodes logically adjacent to the node. The text is concatenated in document order. This allows specifying any text node and obtaining all adjacent text as a single string.

Additional Context

No response

@juanbomfim22 juanbomfim22 changed the title [Bug] colorizeElement method doesn't color the whole text if domNode has more than one #text children [Bug] colorizeElement method doesn't color the whole text if domNode has more than one #text child Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant