开发者

Intercept Visual Studio paste action

开发者 https://www.devze.com 2023-02-02 05:08 出处:网络
Is it possible to intercept the paste event of visual studio in order to transform the text being pasted in? I know I can write my own command to do the smart paste, but it\'s a chore for most people

Is it possible to intercept the paste event of visual studio in order to transform the text being pasted in? I know I can write my own command to do the smart paste, but it's a chore for most people to map this command to a keyboard shortcut. Besides, most peo开发者_开发知识库ple are used to Ctrl+V. Any chance I can plug in my wares in there?


It's a command, and you can handle it by adding a command filter in an extension and handling the command before the editor command handling implementation sees it.

Here's a command handler template. I believe the paste command ID is VSConstants.VSStd2KCmdID.PASTE (using the VSConstants.VSStd2K command guid for the group).

Note, however, that pasting can be much harder than it looks, when you take into account things like pasting box-copied content, pasting into a multi-line selection, empty selection cut/copy and paste, and language service formatting after paste. So, if you are trying to do this with an extension you want to publish, it may be harder than you expect :-/


It must be possible because CodeRush does it. Check out CodeRush xPress and DXCore from DevExpress (http://www.devexpress.com/), they are both free and DXCore gives you some easy ways of hooking into things like that.

0

精彩评论

暂无评论...
验证码 换一张
取 消