sedwards2009 / extraterm

The swiss army chainsaw of terminal emulators
https://extraterm.org
MIT License
2.54k stars 115 forks source link

Copy/paste does not work between other windows and extraterm on Linux #195

Open caedmon-kitty opened 5 years ago

caedmon-kitty commented 5 years ago

On Linux the mouse in combination with a mouse button is used to highlight text and that text is copied. Then another mouse button pastes the copied text into the current windows. I normally use this to copy long commands from one terminal window to another or from one application to another.

This works correctly in all cases except extraterm. It works within extraterm. I can copy some text in the extraterm wiindow and paste it in the same window without problems.

But when I/copy some text in other windows and then try to paste into extraterm instead the last text I copied in extraterm is pasted. All of my text copies outside of extraterm are ignored.

sedwards2009 commented 5 years ago

Here copying between VSCode and Firefox to Extraterm works as expected. Can you tell which application and which actions are needed exactly to see this problem?

caedmon-kitty commented 5 years ago

I've tried these - xterm, mrxvt terminal emulator. Eterm terminal emulator. terminator terminal emulator, emacs Standard X11 setup -

  1. Hold down left mouse button and move mouse to highlight text
  2. Move pointer to extraterm window
  3. Middle button click to paste text. The text pasted is the last text I highlighted in extraterm, not the text highlighted in step 1. Reverse steps 1 and 2 - i.e., copy in extraterm window and paste in another window works.

This also works - between windows other than extraterm:

  1. Step 1 as above in any window
  2. Move to xterm, mrxvt, terminator, emacs window
  3. Paste. Text copied in step 1 is pasted into window.

Also highlight text in extraterm and paste in extraterm works. It looks as if extraterm is not using the X11 provided buffers for paste.

sedwards2009 commented 5 years ago

Thanks for the detailed info.

This is a classic case of X11 having two clipboards. It has a "clipboard" clipboard and a "selection" clipboard. Extraterm only uses the "clipboard" clipboard. (In fact I can't change this. The platform that Extraterm is built on only supports that one clipboard.) Selecting text in xterm and pasting elsewhere using the middle mouse button uses the "selection" clipboard. You can probably still copy text from xterm but first you have to press some shortcut to copy it to the real clipboard.

KDE and perhaps other desktops, have default tools which keep the two X11 clipboards in sync. I don't know which desktop you are using, but running a tool to do the syncing is one possible solution other than explicitly copying to the main clipboard via a shortcut or similar.

Toub commented 4 years ago

In fact I can't change this. The platform that Extraterm is built on only supports that one clipboard.

@sedwards2009 are you talking about electron?

According to the documentation, it looks like the "selection" clipboard is supported as well: https://www.electronjs.org/docs/api/clipboard

On Linux, there is also a selection clipboard. To manipulate it you need to pass selection to each method:

const { clipboard } = require('electron')

clipboard.writeText('Example String', 'selection')
console.log(clipboard.readText('selection'))

Is so, could you please consider to re-open this issue, as it is really disappointing for linux users ?

caedmon-kitty commented 4 years ago

More than disappointing. It makes Extraterm a non-starter for many Linux users. This is basic X11 functionality.

sedwards2009 commented 4 years ago

@Toub Yes I am talking about Electron.

There has been a lot of refinement of the clipboard API in Electron since I did the initial clipboard support. That is a good find in the API docs and I'll be happy to look at it again.

Toub commented 4 years ago

Great!

I had a look at the code, and the clipboard selection option is available in clipboard methods you use in Main.ts.

I guess you will have to duplicate IPC messages (CLIPBOARD_WRITE...).

I am an absolute newbie with Electron but I would be happy to help if I can find a bit of time.

sedwards2009 commented 4 years ago

The simplest thing I can do is when doing a copy inside Extraterm, to copy the text to both clipboards at the same time.

When pasting text, I can fall back to the 'selection' clipboard if the primary one is empty. But that might not be what you want.

The alternative is to add config options for supporting the whole X11 style "selection" clipboard on selection and mouse paste, and the normal clipboard for the rest. But I would like to avoid that if possible. There are only a handful of applications these days which use the X11 'selection' clipboard though.

Toub commented 4 years ago

Thanks for your answer.

The alternative is to add config options for supporting the whole X11 style "selection" clipboard on selection and mouse paste, and the normal clipboard for the rest.

Yes, that's what we need, to have a consistent behavior between the console and other applications.

But I would like to avoid that if possible.

Why? Because it is technically hard, or because you don't want to introduce a new option nor change the current default behavior?

There are only a handful of applications these days which use the X11 'selection' clipboard though.

Are you sure? I think that all applications I use everyday support 'selection' clipboard: firefox, vscode, terminator, file explorer, geany text editor, dbeaver (sql gui client)...

Please find more detail bellow:


==> COPY

Currently, when I select a text inside Extraterm, it copy it to both buffer (so I can paste it using mouse button OR +v).

The simplest thing I can do is when doing a copy inside Extraterm, to copy the text to both clipboards at the same time.

This won't change anything since the selection is already pasted in both buffers.

Is it technically possible to have the following behavior:

Are we able to make a difference between this 2 events?


==> PASTE

Currently, when I paste a text a text inside Extraterm (using mouse button OR +v), the text is always pasted from the main buffer, never the selection one.

This is the most annoying issue, as most of the time, when I copy/paste to the terminal, I use the fast method using the selection buffer.

When pasting text, I can fall back to the 'selection' clipboard if the primary one is empty. But that might not be what you want.

No, that's not. Most of the time there are content in both buffers.

Is it technically possible to have the following behavior:

Are we able to make a difference between this 2 events?


By the way, congratulations for this great project. I really love it and I consider to use it as default terminal emulator if I can solve this issue.

Moreover, as a typescript developer, I would be happy to contribute.

Toub commented 4 years ago

By the way, it can be interesting to have a look at vscode electron clipboard implementation:

sedwards2009 commented 4 years ago

@Toub Thank you for the detailed answer.

I'm hesitant to just add stuff that is only going to affect such a (IMO) small group of people, and may "clutter up" the application. I think that few Linux users are even aware of the two clipboards. I've been using Linux on the desktop since the 90s and haven't been reminded of the X11 clipboard set up for decades. Linux desktop environments have been hiding the two clipboards for a long time already.

That said, one of the my principles for this project is to not ask people to change their terminal habits or workflows if they don't want to, unless it is really unavoidable.


Here's the plan:

That should cover your request.

It is also possible to add a command to "Copy to selection clipboard" which people could then bind their own keyboard shortcuts to, but that doesn't sound necessary if I understand correctly.


Help on this project is welcome, but it is hard to say "where" exactly help is needed.

In intend to keep expanding the Extension API and to more more things into extensions. Extensions will be an area where it is much much easier for new people to get involved.

Toub commented 4 years ago

@Toub Thank you for the detailed answer.

I'm hesitant to just add stuff that is only going to affect such a (IMO) small group of people, and may "clutter up" the application. I think that few Linux users are even aware of the two clipboards. I've been using Linux on the desktop since the 90s and haven't been reminded of the X11 clipboard set up for decades. Linux desktop environments have been hiding the two clipboards for a long time already.

That said, one of the my principles for this project is to not ask people to change their terminal habits or workflows if they don't want to, unless it is really unavoidable.

I understand.

Here's the plan:

* Add a "Copy to 'selection' clipboard" option to the mouse button configuration.

This is probably not necessary, because currently, the selection is already copied to selection clipboard AND default clipboard. I don't understand why. Electron documentation does not mention this.

So, this is current behavior, even when "Automatically copy selection to clipboard" is not checked. Nothing to do here.

* Add an option close to the existing "Automatically copy selection to clipboard" option, where people can select which clipboard should used.

Electron documentation is not clear about what appends when you call clipboard.writeText(text, 'selection') on non-linux system. I suppose that in that case, the text is copied to the default clipboard.

If I am right, no need to add an option, but simply always calling clipboard.writeText(text, 'selection') on selection will do the job.

In that case, there is very few thing to do: just always call this method when using this action:

That should cover your request.

Yes, that cover the COPY behavior part of my request, but this is not the more important, as the "Automatically copy selection to clipboard" workaround is not ideal, but acceptable for now.

It is also possible to add a command to "Copy to selection clipboard" which people could then bind their own keyboard shortcuts to, but that doesn't sound necessary if I understand correctly.

Right.

My main problem is the PASTE behavior. When clicking on middle button, I would like a "Paste from selection clipboard":

image

But as for COPY, this is probably not necessary to add an option for that, depending of Electron clipboard.readText('selection') behavior. I suppose that if selection clipboard is not available, it returns text from default clipboard.

In that case, there is very few thing to do: just always call this method when using this action:

Help on this project is welcome, but it is hard to say "where" exactly help is needed.

In intend to keep expanding the Extension API and to more more things into extensions. Extensions will be an area where it is much much easier for new people to get involved.

Yes, that's a good idea. To begin, I will try to use extraterm for a few days, to see what is missing to me. I already have a few ideas, we can discuss about that in an other issue.

sedwards2009 commented 4 years ago

Sorry. I screwed up my last post. I meant to say: "Add a "Paste from 'selection' clipboard" option to the mouse button configuration.

sedwards2009 commented 4 years ago

To summerise:

Toub commented 4 years ago

To summerise:

* Add "Paste from selection clipboard" option to the mouse settings.

Yes, that's the most important part (but as explained before, probably not necessary to add an option, depending of electron implementation)

* Make sure that copied text goes to both clipboards, regardless of whether it was selected or Ctrl+C.

It is the current behavior.

sedwards2009 commented 3 years ago

@Toub This little feature is now in the nightly build. You can grab a package from here and test it out: https://storage.googleapis.com/extraterm_builds/index.html

Toub commented 3 years ago

Thanks! I just gave a try.

After activating the option, the copy from selection using middle click works. Thanks. Could we make it the default? What appends when you use this option on a non-compatible system?

This is better than before, but there is a related issue:

So, whatever the paste method I use, I always use one of my clipboards.

Is there a reason why the text is automatically selected? It is not a common behavior in other terminals. Could we disable this?

vlisivka commented 3 years ago

I think that few Linux users are even aware of the two clipboards.

The ability to copy-paste text with one hand and just two presses is the main driver to stay on Linux, because it such a huge burst in productivity comparing to other OS'es. It's literary 3x faster than select by mouse -> Ctrl-C -> click by mouse -> Ctrl-V.

All Linux users, which I know, are aware about two-independent-clipboards-feature. Please, don't ruin our user experience.

If you use Windows, you can try https://autoclipx.en.softonic.com/ , https://dragking.en.softonic.com/ , http://fy.chalmers.se/~appro/nt/TXMouse/ .

I think that few Windows users are even aware of the two clipboards.

caedmon-kitty commented 1 year ago

I know this topic has been dormant for awhile but I just tried extratermqt and left mouse copy to selection then paste from selection does not work. It looks like the selected text is copied to the clipboard but not the selection.

Is there a config option I am missing?

niawag commented 1 month ago

Hi, I just installed Extraterm (QT 0.69) and I'm experiencing the same problem that @caedmon-kitty there If I select "Paste from selection clipboard" Extraterm will paste selection from other apps but not from Extraterm If I select "Paste from clipboard" it will be the opposite

It appears that Extraterm always copy the selection in the "main" clipboard, not the selection clipboard so I guess it's a bug. I'm using it on Linux Mint 22 (x64)