VSCODE API:访问MiniMAP
有什么方法可以访问编辑器右侧的滚动条旁边出现的“最小值”?
最好是我想访问该面板的像素宽度。
我能做的最好的值是读取当前的编辑器配置(也可从VSCODE设置UI/JSON进行设置)。
const editorConfig = vscode.workspace.getConfiguration('editor');
const minimapOn = editorConfig.get("minimap.enabled");
const minimapWidth = editorConfig.get("minimap.maxColumn");
但这仅列出最大宽度,而不是当前的宽度。
Is there any way to access the "minimap" that optionally appears next to the scroll bar on the right hand side of the editor?
Preferably I would like to access that panel's width in pixels.
The best I could do to get the values I want is to read the current editor configuration (also settable from the vscode settings UI/JSON).
const editorConfig = vscode.workspace.getConfiguration('editor');
const minimapOn = editorConfig.get("minimap.enabled");
const minimapWidth = editorConfig.get("minimap.maxColumn");
But this only lists the maximum width, not the current one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
配置编辑器小地图的宽度
小地图是可配置的,不是按像素,而是按字符。
它可以按字符配置的原因是它为开发人员提供了一种将小地图宽度设置为最长代码行的精确宽度的方法。这是有益的,因为它使小地图达到所需的宽度,而不占用任何不必要的空间。
下面是更改编辑器小地图宽度的设置。
75 可以设置为您选择的任意数量的字符。
现在是有关 API 的部分
任何时候您有设置完成您想要的操作后,您可以使用 API 将其应用到您的扩展中。我不想继续解释超出此问题范围的任何内容,因此我将提供一个文档链接,其中介绍了使用 VS Code API 更改设置的方法,以及一个代码片段向您展示如何使用该方法更改小地图的列宽。
下面显示了扩展程序可能包含的用于更改小地图大小的代码。
注意:上面的例子是我凭空写出来的。我知道语义都是正确的,但您可能必须使用它才能使其完全按照您的要求进行操作。
这里有几个链接可以帮助您了解您在做什么。
"vscode.workspace.getConfiguration()"
“配置目标” 设置您要定位的 settings.json 文件。 Global 是一个不错的选择,我更喜欢“工作空间”(与“工作空间文件夹”不同)。
Configuring the Width of the Editor's Minimap
The Minimaps with is configurable, not by pixels, but by characters.
The reason it is configurable by characters is because it gives developers a way of setting the minimap's width to the exact width that there longest lines of code are. This is beneficial, as it makes the minimap as wide as needed, without taking up any unnecessary space.
Below is the setting that changes the width of the editor's minimap.
75 can be set to any amount of characters you choose.
Now the part about the API
Anytime you have a setting that does what you want, you can use the API to apply it to your extension. I don't want to continue explaining anything byond the scope of this question, so I will provide a link to the documentation that covers the method used to change a setting using the VS Code API, and a snippet showing you how to use the method to change the minimap's columns width.
Below shows the code an extension might include to change the size of the minimap.
NOTE: I wrote the example above off the top of my head. I know that the semantics are all correct, but you will probably have to play with it to get it to do exactly what it is your going for.
Here are a couple links to help you understand what your doing.
"vscode.workspace.getConfiguration()" This is can be interpreted as the base of program-interface that changes settings. From this part of the API, a few methods, objects, constants, and events extend, all of which are used to set, get, and mutate configurations within VS Code.
"The Configuration target" sets the settings.json file you are targeting. Global is a good bet, I prefer "workspace" (which is not the same as "workspace folder".