microsoft / microsoft/monaco-editor

[Bug] How to remove the previous decorations permanently ?

Open
#4,840 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
goToRefSelection(range: any, editorInstance: ICodeEditor) {
    editorInstance.focus();
    let decorationsCollection = editorInstance.createDecorationsCollection();
    const decorations = [{
      range: new monaco.Range(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn),
      options: {
        inlineClassName: 'go-to-definition-highlight',
      },   
    }];

    decorationsCollection.set(decorations);
    setTimeout(() => {
      decorationsCollection.clear();
      decorationsCollection = null;
      decorationsCollection.set([]);
      
    }, 5000);
    
  }
Reproduction Steps

No response

Actual (Problematic) Behavior

after some duration removing the decoration, but when I call this method next with new decoration, previous decoration is also applying.

Expected Behavior

Need to removing the previous decorations and apply the new decorations.

Additional Context

No response

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 goToRefSelection method in the issue's TypeScript example and review how createDecorationsCollection, set, and clear are used across repeated calls. Reproduce the behavior by invoking the method with successive ranges; done when applying a new decoration no longer leaves the previous decoration visible.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.