更改代码

时间:2018-05-11 20:00:28

标签: visual-studio-code vscode-extensions

我正在研究具有某些模式的vs代码的扩展,我想在我的代码中遇到的某些条件下更改光标颜色(插入符号而不是鼠标光标)。

我也知道我可以使用状态栏项目(我已经更新过),但是我觉得改变你的眼睛已经聚焦的光标颜色将是一个更好的指标,你'以特定模式重新开始。

我有办法在代码中更改它吗?到目前为止我搜索过的内容,我只看到它通过settings.json进行了更改。任何有助于实现这一目标的帮助/推动都将不胜感激!

1 个答案:

答案 0 :(得分:1)

我设法为自己解决了问题。我发布答案,以防其他人将来需要它:

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);

希望能帮助别人。我花了一天的时间进行搜索和实验,直到我得到了这个答案。 :)

相关问题