microsoft / microsoft/monaco-editor

[Bug] The decorator created does not take effect

Open
#4,574 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

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

No response

Actual (Problematic) Behavior

It doesn't really work.

Expected Behavior

I want to render the specified content green

Additional Context
function getPosition(v: string) {
  if (!editor) return;
  const model = editor.getModel()!;
  const content = editor.getValue();
  const startIndex = content.indexOf(v);
  if (startIndex === -1) {
    return;
  }
  const endIndex = startIndex + v.length;
  // Get start and end positions
  const startPosition = model.getPositionAt(startIndex);
  const endPosition = model.getPositionAt(endIndex);

  const startLineNumber = startPosition.lineNumber;
  const startColumn = startPosition.column;
  const endLineNumber = endPosition.lineNumber;
  const endColumn = endPosition.column;

  return { startLineNumber, startColumn, endLineNumber, endColumn };
}

editor.setValue(value);
const position = getPosition(props.data.version);
if (position) {
  const { startLineNumber, startColumn, endLineNumber, endColumn } = position;
  editor.createDecorationsCollection([
    {
      range: new monaco.Range(startLineNumber, startColumn, endLineNumber, endColumn),
      options: {
        inlineClassName: 'version-decorations',
      },
    },
  ]);

.version-decorations {
  font-weight: bold;
  font-style: oblique;
  color: green !important;
}
  

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided getPosition and editor.createDecorationsCollection snippet, then reproduce it in a minimal Monaco editor setup while checking the decoration range and inline CSS class. Done means the specified content renders green; the issue provides no file, test, or complete reproduction to guide further investigation.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.