需求:
标签icon自定义添加显示及标签效果关闭
期望效果:
标签效果
标签关闭效果
实现代码:
let decorateTest:vscode.TextEditorDecorationType ;
const decorationsArray:vscode.DecorationOptions[] = [];
export function activate(context: vscode.ExtensionContext) {
decorateTest = vscode.window.createTextEditorDecorationType(
{
gutterIconPath:context.asAbsolutePath(path.join('pic','marks.png')),
gutterIconSize:'16px 16px'
}
);
}
//标签添加
function addIcon(context:vscode.ExtensionContext){
const line = vscode.window.activeTextEditor?.selection.active.line;
const lineNum = line ? line : 0;
const edit = vscode.window.activeTextEditor;
const rangeValue = new vscode.Range(new vscode.Position(lineNum,0),new vscode.Position(lineNum,0));
const tt = {range:rangeValue,hoverMessage:'这是装饰器的提示语'};
decorationsArray.push(tt);
edit?.setDecorations( decorateTest,decorationsArray);
}
//标签删除
function deleteIcon(context:vscode.ExtensionContext){
const line = vscode.window.activeTextEditor?.selection.active.line;
const lineNum = line ? line : 0;
const edit = vscode.window.activeTextEditor;
decorateTest.dispose();
edit?.setDecorations( decorateTest,decorationsArray);
}
你的打赏是对媛媛的认可支持,也是动力来源,感谢~~~~
版权声明:本文为qq_25550711原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。