我正在开发 VS Code 的扩展,它具有某些模式,并且我想在代码中满足某些条件时更改光标颜色(插入符号而不是鼠标光标)。
我也知道我可以使用状态栏项目(我已经更新了),但是我觉得更改光标的颜色(您的眼睛已经聚焦的位置)将更好地表明您“处于某种模式。
有办法在代码中更改它吗?到目前为止,从我搜索到的内容来看,我只看到它是通过 settings.json 进行更改的。任何帮助/插入实现这一目标的正确方向将不胜感激!
最佳答案
我自己设法解决了这个问题。我发布答案以防其他人将来需要它:
const configuration = vscode.workspace.getConfiguration('workbench');
//get settings for workbench where colorCustomizations is present
configuration.update('colorCustomizations', {"editorCursor.foreground": "#FF0000"}, true);
//true will make it apply to global settings (your user settings.json)
如果你想恢复原来的光标颜色,有两种方法
1)
configuration.update('colorCustomizations', {"editorCursor.foreground": undefined}, true);
//this deletes the colorCustomizations setting on your user settings
2)
const CURSOR_FOREGROUND = new vscode.ThemeColor('editorCursor.foreground');
//make a backup of the current color in your theme
configuration.update('colorCustomizations', {"editorCursor.foreground": CURSOR_FOREGROUND},true);
希望能帮助别人。我花了几天的时间进行搜索和实验,直到得到这个答案。 :)
关于visual-studio-code - 更改代码中光标的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50299443/