oni icon indicating copy to clipboard operation
oni copied to clipboard

`set clipboard=unnamed` and duplicating the line

Open zindel opened this issue 8 years ago • 11 comments

First of all let me thank all the team for working on it! I was surprised how smoothly it runs and handles my current nvim configuration almost without exceptions.

Oni Version: 0.3.4 Neovim Version (Linux only): Operating System: MacOS Sierra 10.12.2

Describe your issue

Yp shortcut is broken when oni.loadInitVim is set to true and init.vim contains the set clipboard=unnamed line.

Steps to reproduce

Create the minimal oni-test-init.vim containing just this:

set clipboard=unnamed

Specify the configuration setting in the config.tsx as following:

...
"oni.loadInitVim": "/path/to/oni-test-init.vim"
...

Restart Oni. In any text editing window:

  1. Go to Insert mode (i)
  2. Type "test" (test)
  3. Go back to normal mode (Esc)
  4. Duplicate the line (Yp or yyp)

Expected behaviour

test
test

Actual behaviour

testtest

The issue is not critical. There is a workaround:

if !exists("g:gui_oni")
  set clipboard=unnamed
endif

But very annoying when you hit it for the first time.

Once again thank you for working on it!

zindel avatar May 30 '18 11:05 zindel

Hello and welcome to the Oni repository! Thanks for opening your first issue here. To help us out, please make sure to include as much detail as possible - including screenshots and logs, if possible.

oni-bot avatar May 30 '18 11:05 oni-bot

Hi, @zindel !

Thanks for logging this! Personally, I suffered with this issue up until now and kept wishing it to be fixed. Just tried your solution and it seems to work great!

@bryphe, do you think Oni should handle it on boot? I think of something like:

if ((clipboard == 'unnamed' || clipboard == 'unnamedplus') &&
    SOME_USER_CONFIG_THAT_DEFAULT_TO_TRUE) {
    clipboard = '' // I think that this is the default value
}

TalAmuyal avatar May 30 '18 15:05 TalAmuyal

Well, after a day of work w/o set clipboard=unnamedplus I am at a loss. This setting is a life-quality requirement, but so is the the validity of yyp, yyP, ddP etc.

Anyone has an idea of how to fix this so that both will work at the same time?

TalAmuyal avatar May 31 '18 12:05 TalAmuyal

@TalAmuyal what is the problem you are getting? Selection works well for me inside Oni & the console nvim as well. I am on MacOS though

zindel avatar May 31 '18 13:05 zindel

I use Mac too.

The issue is thus:

If I set clipboard to unnamedplus then

  1. The system-clipboard and the default vim-register are the same and thus I can <CMD-C> in Google Chrome and p in Oni
  2. I have the same issue that you described at the beginning of this thread.

On the other hand, if I remove the setting of clipboard then

  1. I loose the ability to freely copy-paste between Oni and the rest of the OS
  2. Line-wise copy-paste inside Oni works as expected.

I want both having "line-wise copy-paste inside Oni work as expected" and "the ability to freely copy-paste between Oni and the rest of the OS".

TalAmuyal avatar May 31 '18 14:05 TalAmuyal

So, just verified on my own, here is what I am getting:

  1. If I do :set clipboard in Oni, I get clipboard=
  2. Copying from Oni to other windows (for example, Chrome)
  • Y in Oni
  • Cmd+V in Chrome Works!
  1. Copying from Chrome to Oni
  • Select text and Cmd+C in Chrome
  • Normal mode in Oni, p Doesn't work, getting the context of the last deleted line in Oni
  • Insert mode in Oni, Cmd+V Works! Getting content of the Chrome selection

So, the issue exists, but as usually, there is a workaround :)

zindel avatar May 31 '18 15:05 zindel

Just tried setting "editor.clipboard.enabled": false, in Oni's config and it seems to work fine with set clipboard=unnamedplus. Will give it a try for a work-day or two and will report back.

TalAmuyal avatar Jun 01 '18 05:06 TalAmuyal

Glad there is a workaround! Let me know if that doesn't work, @TalAmuyal . And thanks for the kind words and thoughtful investigation, @zindel !

I'm guessing that there is some interplay here: https://github.com/onivim/oni/blob/a34e1d64ecf529f2d31f5f0bbb9cc33c4d19980e/browser/src/Editor/NeovimEditor/NeovimEditor.tsx#L423

When editor.clipboard.enabled is true, Oni on yank will set the clipboard directly. It might be that it's not properly passing up a new line or paving the clipboard. A potential fix might be to ditch this behavior if the user explicitly sets clipboard - if a user explicitly sets clipboard, we can assume they know exactly what behavior they want.

The only downside is there is a complicated interplay of settings between editor.clipboard.enabled and set clipboard - perhaps there is a way we could streamline this or make it more intuitive?

bryphe avatar Jun 02 '18 18:06 bryphe

Got a private branch with a fix, will post a PR soon.

TalAmuyal avatar Jun 05 '18 14:06 TalAmuyal

PR: https://github.com/onivim/oni/pull/2298 Will appreciate feedback for for the code-change and for actual functionality :)

TalAmuyal avatar Jun 08 '18 11:06 TalAmuyal

Should be fixed now in master. Please note if there are more inconsistencies.

TalAmuyal avatar Jun 14 '18 11:06 TalAmuyal