Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Truncated copy/paste #2414

Closed
Piping opened this issue Jul 9, 2018 · 8 comments
Closed

Truncated copy/paste #2414

Piping opened this issue Jul 9, 2018 · 8 comments

Comments

@Piping
Copy link

Piping commented Jul 9, 2018

**Oni Version: **
Operating System: windows

Issue:
Copy a large number of lines into Oni and only got paste partially.

@CrossR
Copy link
Member

CrossR commented Jul 9, 2018

Confirmed using the csv file we have in test/collateral/, copied the raw file from GitHub and pasted into Oni and got 975 lines and 1 partial line, rather than 1000 lines. Pasting into Notepad++ (to prove the file was fully copied) worked fine.

Copying/pasting directly inside Oni (with y/p) is fine, only copying from outside Oni and pasting in seems to be broken.

The way we read the clipboard (clipboard.readText()) seems to be the only way to do so, so I think the issue lies in the use of nvim_input rather than nvim_set_lines?

@akinsho
Copy link
Member

akinsho commented Jul 21, 2018

Hopefully this is a good first issue the related code is here I believe the steps to resolve this would be first confirming that clipboard.readText() isn't clipping the text if not then as @CrossR suggested I think switching to using neovimInstance.setLines would be preferable docs here

It would be interesting to know why the input function is truncating the input as this maybe an issue we ought to raise with neovim or we might be using the method incorrectly

@psxpaul
Copy link
Contributor

psxpaul commented Aug 14, 2018

I took a quick look at this over the weekend, and here are a few things I found:

  • clipboard.readText() is not clipping, but neovimInstance.input(sanitizedText) is. The documentation for nvim_input() here seems to indicate that clipping will occur if the buffer becomes full.
  • Using <c-v>/<m-v> to paste even short text, then using the repeat operator (.) results in all pastes after the first one to have incorrect indentation. I believe this is because set paste and set nopaste are not invoked with the repeat operator.
  • Using nvim_buf_set_lines like BufferManager.setLines would likely break the repeat operator in a different way. Issue Oni completions are not dot repeatable #2501 has some more information on that.
  • The Edit->Paste, Edit->Paste Line Before, and Edit->Paste Line After do not seem to suffer from the truncation issue. They are executing the \\"+gP, [p, ]p commands respectively, instead of simulating user input.
  • The Edit->Paste menu command seems to paste before the current cursor, which doesn't seem correct to me. At the very least, it is different from the <c-v>/<m-v> behavior.
  • With the setting "editor.clipboard.synchronizeYank": false, <c-v>/<m-v> will do a vim yank, but not update the system clipboard. This seems weird to me as well, because I don't want normal yanks to stomp on my system clipboard, but I do want / to copy to the clipboard.

The simplest approach to me would be to change the editor.clipboard.paste command to just execute "+p, but from bryphe's comments in #628, the current approach was used to workaround issues with win32yank on Windows.

@akinsho
Copy link
Member

akinsho commented Aug 19, 2018

@psxpaul thanks for investigating what was going on here and for the detailed feedback 👍, I think the "+p solution you mentioned would be the simplest and arguably best although I'm not sure how many people the win32yank issue affects(not sure I fully understand it from the linked issue) but atm the workaround seems to affect everyone and breaks pasting into oni 😞, meanwhile the "+p solution is the vim way of handling this issue i.e. Not sure oni needs to do anything special here rather than just let vim handle things (although I could be wrong and there is a special requirement here)

@CrossR
Copy link
Member

CrossR commented Aug 19, 2018

It may be worth trying using "+p again, since we do include win32yank on Windows, and it works across my 3 machines.

Maybe added as a config option and the devs/insiders give it a try for a bit and then make it the default?

psxpaul added a commit to psxpaul/oni that referenced this issue Aug 20, 2018
psxpaul added a commit to psxpaul/oni that referenced this issue Aug 20, 2018
psxpaul pushed a commit to psxpaul/oni that referenced this issue Aug 20, 2018
akinsho pushed a commit that referenced this issue Aug 27, 2018
This is a fix for some of the issues raised in #2414. One thing to note - there was some question as to whether win32yank works for everyone. I did find a possible workaround for that, if it's still an issue:

```
const textToPaste = clipboard.readText()
const sanitizedTextLines = replaceAll(textToPaste, { "'": "''" })
await neovimInstance.command("let @+='" + sanitizedTextLines + "'")
```

I don't have a windows box to test this on, so perhaps we can add this code to `NeovimEditorCommands. pasteContents` later if needed.
@psxpaul
Copy link
Contributor

psxpaul commented Sep 1, 2018

Can this be closed now?

@badosu
Copy link
Collaborator

badosu commented Sep 3, 2018

@psxpaul Did you reproduce the error previously and confirm it is fixed now?

@CrossR
Copy link
Member

CrossR commented Sep 3, 2018

I've tested the test case I gave and it is fixed for that, so I'll close this out now! Cheers @psxpaul !

@CrossR CrossR closed this as completed Sep 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants