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

Decoration disappeared after switching editor #17872

Closed
XuJiandong opened this issue Dec 28, 2016 · 3 comments
Closed

Decoration disappeared after switching editor #17872

XuJiandong opened this issue Dec 28, 2016 · 3 comments
Assignees
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)

Comments

@XuJiandong
Copy link

  • VSCode Version: 1.8.1
  • OS Version: Window 7

Steps to Reproduce:

  1. use the following code to mark some word,e.g.:
MarkWord(vscode.window.activeTextEditor, "hello", "hover message", 1, 10)

export function MarkWord(editor: vscode.TextEditor, word: string, hover: string, startLine: number, endLine: number) {
    let decorationType = vscode.window.createTextEditorDecorationType({
        outline: '1px dotted red'
	});
    let regEx = /\w+/g;
    let decoratedWords : vscode.DecorationOptions[] = [];
    for (let i = startLine; i <= endLine; i++) {
        let lineText = editor.document.lineAt(i).text;
        let match;
        while (match = regEx.exec(lineText)) {
            if (match[0] == word) {
                let startPos = new vscode.Position(i, match.index);
                let endPos = new vscode.Position(i, match.index + match[0].length);
                let rg = new vscode.Range(startPos, endPos);
                decoratedWords.push({ range: rg, hoverMessage: hover});
            }
        }
    }
    editor.setDecorations(decorationType, decoratedWords);
}
  1. Switch to another editor tab, then switch back, all decorations disappeared
@rebornix
Copy link
Member

When an editor becomes invisible, whether it's inactive or closed, we'll always remove all decorations bind to the model of the editor. You may want to register a handler to active editor change event and add decorations when the editor is active.

@rebornix rebornix added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Dec 29, 2016
@XuJiandong
Copy link
Author

thank you rebornix. Hope it can be added into the document.

@rebornix
Copy link
Member

@XuJiandong sorry for the misleading, we'll write documentation to explain things under the hood.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*question Issue represents a question, should be posted to StackOverflow (VS Code)
Projects
None yet
Development

No branches or pull requests

3 participants