Repository navigation
Closed
Labels
Milestone
Description
- VSCode Version: 1.7.1
- OS Version: Windows 10 14965
Steps to Reproduce:
- Create a text decoration that is applied to where the cursor is (easy example is decoration at line 0, char 0-1 on an empty document)
- Start typing
- Decorator is applied correctly to first letter
- Delete all text
- Type again, decorator is applied to everything instead of just first letter
'use strict';
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
var activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
updateDecorations(activeEditor);
}
vscode.window.onDidChangeActiveTextEditor(editor => {
activeEditor = editor;
if (editor) {
updateDecorations(activeEditor);
}
}, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
updateDecorations(activeEditor);
}
}, null, context.subscriptions);
vscode.workspace.onDidChangeTextDocument(event => {
if (activeEditor && event.document === activeEditor.document) {
updateDecorations(activeEditor);
}
}, null, context.subscriptions)
}
function updateDecorations(activeEditor : vscode.TextEditor) {
if (!activeEditor) {
return;
}
let firstLetterDecoration = vscode.window.createTextEditorDecorationType({color: "#ff0000"});
let range = new vscode.Range(new vscode.Position(0,0), new vscode.Position(0,1));
activeEditor.setDecorations(firstLetterDecoration, [range]);
}
// this method is called when your extension is deactivated
export function deactivate() {
}
Activity
[-]setDecorations Range Cursor interaction[/-][+]setDecorations Range new text interaction[/+]alexdima commentedon Nov 30, 2016
CoenraadS
1. Decorations "move" with the text
If you add a decoration, say at a certain range such as [0,0 - 0,1], typing (inserting text) inside that range or on the edges of the range causes the decoration to grow.
2. The code inserts very many decorations
The sample you have provided, creates a new decoration editor type on each keystroke and sets that type to a new decoration on each keystroke (i.e. N keystrokes => N decoration types each with one decoration), meanwhile they never get removed. i.e. move
createTextEditorDecorationTypeto theactivatemethod or in a static context or dispose the decoration type when you are no longer wanting it.i.e.

CoenraadS commentedon Dec 4, 2016
Would it be possible to add stickiness as a decoration option? I see something already exists that is similar.
[-]setDecorations Range new text interaction[/-][+]Expose decorations stickiness to extensions[/+]1 remaining item
CoenraadS commentedon May 2, 2017
Would a PR for this be accepted? And if so would it be possible for a beginner?
CoenraadS commentedon May 16, 2017
alexandrudima
Do you have time to take a look at this? A PR is ready.
Merge pull request #25776 from CoenraadS/stickyness_api
alexdima commentedon May 30, 2017
e.g. for verification: