更改代码中光标的颜色 [英] change the color of the cursor in code

查看:80
本文介绍了更改代码中光标的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为VS代码开发一个扩展,它具有某些模式,我想在代码中满足的特定条件下更改光标颜色(插入符号而不是鼠标光标)。

我也知道我可以使用状态栏项目(我已经更新了),但我觉得更改光标的颜色会更好地指示您处于某种模式。

有没有办法在代码中更改它?到目前为止,我只看到通过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);

希望这对某人有帮助。我花了几天的时间寻找和试验,才得到这个答案。:)

这篇关于更改代码中光标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆