monaco-vim icon indicating copy to clipboard operation
monaco-vim copied to clipboard

Paste in visual mode does not replace last character

Open jsmith opened this issue 3 years ago • 1 comments

When pasting in visual mode, the last character in the selection (the character under the cursor) is not replaced. To reproduce, enter into visual mode, make a selection, press yank, make the same selection again, and then paste.

I tried to dig into this a bit and noticed that, when yanking, there is a one character offset added to either the head or the anchor (see makeCmSelection, L3116 to L3119). This doesn't happen when pasting. I came up with a naive solution by adding 1 to selectionEnd.ch after L2597:

var selectionEnd = selectedArea[1];

// Added the following two lines
selectionEnd.ch += 1;
cm.setSelection(selectionStart, selectionEnd)

var selectedText = cm.getSelection();

It would be great to get this behavior fixed so that it mimics vim :) Thanks so much!

jsmith avatar Nov 15 '21 11:11 jsmith

Likely related: https://github.com/googlecolab/colabtools/issues/2748

eavesjump avatar May 27 '22 16:05 eavesjump