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

Clipboard pastes per line #628

Closed
cyansprite opened this issue Aug 18, 2017 · 8 comments
Closed

Clipboard pastes per line #628

cyansprite opened this issue Aug 18, 2017 · 8 comments

Comments

@cyansprite
Copy link
Contributor

Copy a lot of lines of text and use c-v, it will go through each line an insert it slowly.

const pasteContents = (neovimInstance: INeovimInstance) => {
    const textToPaste = clipboard.readText()
    const sanitizedText = replaceAll(textToPaste, { "<": "<lt>" })
    neovimInstance.input(sanitizedText)
}

I think it might be better to use norm! "+p?

@CrossR
Copy link
Member

CrossR commented Aug 18, 2017

This might also help something I've noticed on my machine where I get a space between each copied line.
I copy:

  "oni.statusbar.enabled": false,
  "editor.clipboard.enabled": true

but when I paste I get

  "oni.statusbar.enabled": false,

  "editor.clipboard.enabled": true

It is being brought into the clipboard correctly, as other editors are fine with pasting it, its just pasting into oni.

@bryphe
Copy link
Member

bryphe commented Aug 18, 2017

Thanks for logging this! It seems like there are a few issues with multiline text (newlines, formatting).

For multine line pasting, it might be better to set the buffer line(s) directly, as opposed to simulating typing in insert mode.

I think it might be better to use norm! "+p?

Unfortunately this doesn't work for me on Windows - I've tried a few different settings for set clipboard in my init.vim. Is there anything special you had to set to enable this?

@CrossR
Copy link
Member

CrossR commented Aug 18, 2017

With "oni.useDefaultConfig": true, and "oni.loadInitVim": false, using :norm! "+p worked for me at least, and without any newlines.

I could Ctrl+c and then use that command and it pasted at the cursor position.

@cyansprite
Copy link
Contributor Author

cyansprite commented Aug 19, 2017

Unfortunately this doesn't work for me on Windows - I've tried a few different settings for set clipboard in my init.vim. Is there anything special you had to set to enable this?

@extr0py Use
´´´:CheckHealth´´´
And make sure the clipboard provider is set.
You need xsel on linux and I'm not sure what the one is for windows... I remember reading the docs a long time ago when I first downloaded it, we can always provide it WITH neovim binary.

Or optionally and a more complex solution...
We can bypass the neovim clipboard provider assuming the user doesn't want to try fix the issue, we can save a register override it with the contents of oni clipboard (if it contains more than one line use V, if one line use character wise v and we wont use c-v because we can't copy like that outside of vim.)

With "oni.useDefaultConfig": true, and "oni.loadInitVim": false, using :norm! "+p worked for me at least, and without any newlines.

Thanks for the feedback. @CrossR!

@CrossR
Copy link
Member

CrossR commented Aug 20, 2017

I've realised that the "Paste" option under the Edit menu does this similarly to the way @cyansprite is proposing.

click: (item, focusedWindow) => executeVimCommand('\\"+gP')

So if there is issues around it not working it may affect there too.

@cyansprite
Copy link
Contributor Author

So if there is issues around it not working it may affect there too.

I think we should assume the user will have clipboard support, if not that is a neovim issue not an oni issue.

click: (item, focusedWindow) => executeVimCommand('\\"+gP')

we already handle it this way here, so we should handle it the same way else where.

@extr0py what are your thoughts on this?

@bryphe
Copy link
Member

bryphe commented Aug 20, 2017

Hmm, thanks for the ideas, I tried :CheckHealth, and I do see an issue here:

## Clipboard (optional)
  - SUCCESS: Clipboard tool found: win32yank

But then I get this when I try "+y:
image

I've done this a few times though in the past, and occasionally ### Clipboard does not report SUCCESS. Not sure why :( And there was a time it did work (prior to upgrading Neovim), but it actually was really slow - it would call win32yank every d/y operation, and somehow that was noticeably slow.

I think there are some ways we can make the strategy in work:

  • call set paste prior to pasting (this turns off autoindent and speeds up the insertion)
  • prune the /r/n newlines on windows, since those are causing duplicate newlines

And I think having a JS code path that touches paste might be valuable. Some things I was thinking about later, in terms of extending this, would be like pasting an image - it'd be cool if we had github-like behavior to upload the image in the background and paste in the link. I don't believe some of those extension points would be easy / possible if we use the external provider.

Good point on the menu provider... For that,, we should have that invoke the editor.clipboard.paste command (which should be the unified entry point for paste behavior - accessible from menus, keybindings, etc), and then expand that binding to handle different modes.

@cyansprite
Copy link
Contributor Author

That is an excellent point, I'm use to using "+y/p/d on linux, and it's pretty fast.

call set paste prior to pasting (this turns off autoindent and speeds up the insertion)
prune the /r/n newlines on windows, since those are causing duplicate newlines

This sounds good.

images

Sounds pretty awesome, future ways to be more extensible should be factored in and I haven't thought about that.
I can do some more research on the topic to see how pasting might be even quicker.

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

3 participants