Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paste though mouse middle button does not insert text at cursor position #5065

Open
jordanauge opened this issue Jul 22, 2020 · 12 comments
Open

Comments

@jordanauge
Copy link

jordanauge commented Jul 22, 2020

Describe the bug
In addition to the text being incorrectly placed, sometimes other text also seems "randomly" deleted.

Although close to #4405, or other entries related to mouse/cursor interfaces, this one might deserve another entry.

To Reproduce

  1. Select some text through selection (eventually outside of VSCode)
  2. Place the VIM cursor where you want the insertion to take place and enter insertion mode.
  3. Middle-Click in the VS code window to trigger the paste.
  4. The text is pasted at the line where the click occurs, and not at the line where the cursor is. We remark that after the paste the cursor has not moved.
  5. Eventually, parts of the original document are scrambled.

Expected behavior
In Vim (:set mouse=a), the paste occurs where the cursor is, not where the mouse clicked.

Environment :

Extension (VsCodeVim) version: v1.16.0
VSCode version: 1.47.2
OS: Debian/bullseye

@J-Fields
Copy link
Member

How do you get middle mouse click to paste?

@jordanauge
Copy link
Author

Nothing special, it just works by default in my KDE environment. If I paste middle-clicking on the line where the cursor is, it works as expected.

@J-Fields
Copy link
Member

J-Fields commented Jul 22, 2020

Got it. My guess is that middle click is the same as left click then paste? In that case fixing #4405 would probably resolve this as well (actually maybe not. I think the only way of "ignoring" the mouse click at this point is to detect the selection change, then reset the selection to where it was, but if the paste happens before we have the chance to do that, we'd be out of luck)

@jordanauge
Copy link
Author

The clipboard buffers are different with paste from the contextual menu (it pastes the Ctrl+C'ed selection, not the last selection). The position taken into account is where the right-click was done, but this time it moves the cursor.
None of the two ways allow to paste where the VIM cursor is positioned.

@berknam
Copy link
Contributor

berknam commented Jul 22, 2020

If the cursor is changing that means vscode is sending a selection change event which means it is probably the same as left click then paste.

@jordanauge Can you confirm if the cursor moves in vscode even without this extension?

If that is the case, from what I've been looking into selection changes I'm pretty sure you can't guarantee that you'll be able to reset the cursor before the paste. It might work most of the times (even though it will flicker the cursor), but if for some reason the extension host is busier it will probably not work.

@jordanauge
Copy link
Author

jordanauge commented Jul 22, 2020

What I understood is that VScode seems to make a selection of what is between the current cursor position, and the position pointed by the mouse click (either middle or right click, and which explains why cursor disappears), and replaces it with the pasted text. When disabling the VIM extension this behaviour is pretty obvious, and the cursor moves after middle-click paste.

What has confused me is that with the vim extension, the vim cursor is not moving at all in the case of a middle click paste (only moving when right-clicking), and this is confirmed by typing some text after the paste. Still, the paste has replaced the would-have-been-otherwise-selected text, consistently with the previous test.

I hope this is more clear, summarized:

  • no vim extension / middle click -> cursor moves
  • no vim extension / right click -> cursor moves
  • vim extension / middle click -> cursor doesn't move (my initial report)
  • vim extension / right click -> cursor moves

In VIM I am used to the click position not being taken into account during paste, which makes it easy to insert something at the cursor position.

@berknam
Copy link
Contributor

berknam commented Jul 22, 2020

vim extension / middle click -> cursor doesn't move (my initial report)

That's strange! I've just looked into vscode source and they are definitely changing the cursor to the click position when you middle click. So that should send us the selection change to move the cursor (now the paste could happen before or after this event), but after the paste we should get another selection change and again update the cursor.

I don't have any linux machine right to now to test this. Could you try and build a version of this extension from PR #5050? I've included on that PR some debug information from selections. If you can do that and then set "vim.debug.loggingLevelForConsole": "debug", check the console from the developer tools to see the debug information!

If you need any help on any of those steps just tell me.

@jordanauge
Copy link
Author

jordanauge commented Jul 22, 2020

I tested with your branch and the behaviour is now coherent with the rest of VS code (the cursor now moves).
This is not however the expected behaviour for vim (cursor should not move and paste should be made from its location, whether it is a middle-click or right click/Paste). Is it a limitation of the extension API ?

Just fyi, i faced those little issues:

  • during Build: "could not find the task gulp: build-dev" (easily fixed)
  • after paste: TaskQueue: Error running task. getLineLength() called with out-of-bounds line 7. (i did not investigate)

@berknam
Copy link
Contributor

berknam commented Jul 22, 2020

I think this issue should be open in vscode. With the current vscode API Idon't think we can make this work the way you want properly for the reasons stated above.

What is the normal behavior of middle-click paste on other applications or other editors? Does it move the cursor? If it doesn't move the cursor then that is clearly a reason to open up an issue in vscode repo stating this as a bug.

If it it moves the cursor even in other applications (except Vim like you mentioned) than you can always try to open a feature request issue in vscode asking them to at least make a configuration for that so that you enable or disable the cursor moving when you paste with middle button.

@berknam
Copy link
Contributor

berknam commented Jul 22, 2020

I've tried to make this change and package vscode but for some reason I'm not able to package vscode. If you want you can try this branch I made with a possible fix for that on vscode. You will have to build and run vscode from that branch to test it. Check here to know how to do that.

I'm not able to test it, but it should work.

@jordanauge
Copy link
Author

jordanauge commented Jul 23, 2020

Thank you. I will try to dedicate some time to test this patch to vscode.

While digging up, i noticed that the text being selected and thus replaced is me unnoticingly pressing SHIFT during paste as I tend to do in vim to altern between xtern and vim modes. Sorry for the confusion. On that point, the behaviour of vscode is pretty consistent, and it is better exploiting the shift modifier than others, say kate in the list hereafter.

Still, the default behavour in vim seems not to mouse cursor in either mouse mode (if someone could confirm).

Definitely this not a bug related to the vim plugin, and it should instead be a feature request to vscode, allowing the plugin to implement an option to emulate vim mouse management if chosen by the user. Not sure this should remain open in the meantime, or requalified as a feature request ?

--

I'll log here my tests with the different editors:

vim:

  • middle click : does not select, does not move cursor (in neither xterm nor vim modes, see:help mouse)
  • SHIFT+middle click : does not select, does not move cursor (in neither xterm nor vim modes, see:help mouse)

kate:

  • middle click : does not select, moves cursor before paste
  • SHIFT+middle click : does not select, moves cursor before paste

vscode (extensions disabled):

  • middle click : does not select, moves cursor before paste
  • SHIFT+middle click : selects, moves cursor before paste

@nahuel
Copy link

nahuel commented Jan 29, 2023

Reported before at microsoft/vscode#97387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants