VS Code extension API for registering pointer down and up and translating coordinates to line/character position

微笑、不失礼 提交于 2021-02-08 10:33:14

问题


I have developed a VS Code Box Drawing extension which works by using selection's start and end positions to work out a level rectangle between the two positions in the text and replaces the edge characters of the rectangle with Unicode box drawing characters.

This works great with a selection start and end positions provided, but it also requires at least white space to already extend all the way to the right edge of where the box is supposed to end, otherwise the selection cannot be made that far.

I would like to achieve two things:

  1. Be able to use mouse events and figure out would-be positions from them even if they extend beyond the length of the lines, so that I can back-fill the missing line length with white-space as I go drawing the box.
  2. Be able to draw arrows (simple enough using the Bresenham's line algorithm).

I have read the Visual Studio Code API Reference and it has only one mention of the mouse pointer in this section underneath the languages header:

The rest, like tracking the mouse, positioning the hover, keeping the hover stable etc. is taken care of by the editor.

I have also read through the Extensibility Reference finding nothing relevant to what I aim to achieve.

This extension only makes sense for monospaced fonts, so additionally, I'd like to find out if there is a way to tell if the editor font is monospaced so I can reject extension activation with an error if that's not the case.


回答1:


This is something the VS Code team doesn't currently enable (not a part of the extension API) not wants to enable in the near future:

I think that exposing mouse events to the extension API is not something that we'd be likely to add

Source comment on GitHub



来源:https://stackoverflow.com/questions/49672961/vs-code-extension-api-for-registering-pointer-down-and-up-and-translating-coordi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!