visual-studio-code - 更改代码中光标的颜色

标签 visual-studio-code vscode-extensions

我正在开发 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/

相关文章:

visual-studio-code - GitHub Copilot 的恼人声音在 Visual Studio Code 中提出内联建议时

visual-studio-code - Visual Studio Code (VSCode) 如何根据当前工作区推荐要安装的扩展?

svelte - VSCode扩展-多个webview之间的数据共享

bash - VScode 终端似乎没有在 Windows 上加载 .bashrc 或 .bash_profile

html - Web 组件的自定义 HTML 代码段

visual-studio-code - 如何在不影响编辑器内代码字体大小的情况下使 Visual Studio 代码侧边栏更小

ubuntu - 如何在 VSCode + Vim + Ubuntu 中使用其他语言(例如俄语)而不自行更改布局?

powershell - 如何查找用于PowerShell集成控制台的profile.ps1文件?

c# - 在 Visual Studio Code 中发布构建

typescript - 如何使用 vscode 扩展 api 将命令放入子菜单