zed icon indicating copy to clipboard operation
zed copied to clipboard

linux: Fix backspace copying characters to primary clipboard

Open apricotbucket28 opened this issue 1 year ago • 8 comments

Closes https://github.com/zed-industries/zed/issues/14362

This PR moves the primary clipboard writing logic of the editor crate to mouse up, instead of selections_did_change. This prevents actions like Backspace from copying to the primary clipboard.

Selecting with the keyboard also no longer copies to the primary clipboard, but this seems to vary from program to program.

Release Notes:

  • Linux: Fixed backspace copying characters to primary clipboard.

apricotbucket28 avatar Aug 13 '24 21:08 apricotbucket28

Warnings
:warning:

This PR includes links to the following GitHub Issues: #14362 If this PR aims to close an issue, please include a Closes #ISSUE line at the top of the PR body.

Generated by :no_entry_sign: dangerJS against 826e8ad411e41c4db306f4ddad03b0f3378ecb6c

zed-industries-bot avatar Aug 13 '24 21:08 zed-industries-bot

Backspace and Copying reminded me of the keybinding showing up weirdly in my linux system (fedora 40, wayland). I suppose this is a different issue. Is this a known issue or should I file a new issue. I think Cut, Copy and Paste should be Ctrl+X, Ctrl+C and Ctrl+V?

image

joelselvaraj avatar Aug 14 '24 05:08 joelselvaraj

Backspace and Copying reminded me of the keybinding showing up weirdly in my linux system (fedora 40, wayland). I suppose this is a different issue. Is this a known issue or should I file a new issue. I think Cut, Copy and Paste should be Ctrl+X, Ctrl+C and Ctrl+V?

The keyboard shortcuts shown in the menu and the ones you mentioned are all valid for their respective actions. I agree that the shown keybindings should be Ctrl+X, Ctrl+C and Ctrl+V (since those are what all other programs show). IIRC this is because of how GPUI handles keybindings internally (insertion order is ignored). I haven't really looked at that code, so I might be wrong.

Nevertheless, that issue is different from what this PR is trying to address. You should file a new issue if one doesn't already exist.

apricotbucket28 avatar Aug 17 '24 01:08 apricotbucket28

@apricotbucket28 This seems like a reasonable change to me, is it still a draft for a reason?

ConradIrwin avatar Aug 22 '24 19:08 ConradIrwin

@ConradIrwin The previous primary clipboard implementation was broken because deleting a character actually selects the character before the cursor, and replaces that selection with nothing. This would fix this issue, but introduces a new one where selecting text with the keyboard would not add it to the primary, only when selecting it with the mouse.

The real solution would most likely introduce some sort of intent given to the function that selects text, so that it can differentiate between something that happened due to some zed internal implementation details like deleting a character, or if it was a user action.

phisch avatar Aug 22 '24 19:08 phisch

Makes sense.

I don't know if we have a way to say "user manually changed selection" yet. One idea would be to put it into the Editor::select* methods directly; but that won't catch edge cases like jump to definition / search result which create a selection (though maybe that's actually good?).

Another idea would be to register for the SelectionsChanged event from the editor - this will only be fired once per update so you won't see the intermediate selected characters in backspace - would that work?

ConradIrwin avatar Aug 22 '24 22:08 ConradIrwin

Unfortunately it seems like the SelectionsChanged event is fired from the same place that currently writes to the primary clipboard: https://github.com/zed-industries/zed/blob/b1a581e81b6eaa951a7ca195cb0c46c335d0d5c7/crates/editor/src/editor.rs#L2288 https://github.com/zed-industries/zed/blob/b1a581e81b6eaa951a7ca195cb0c46c335d0d5c7/crates/editor/src/editor.rs#L2415

apricotbucket28 avatar Aug 22 '24 23:08 apricotbucket28

@apricotbucket28 Right, but it's not received by listener until after the current cx.update has completed (at which point backspace will have resolved).

ConradIrwin avatar Aug 23 '24 03:08 ConradIrwin

@apricotbucket28 do you want to pair on this? https://calendly.com/conradirwin/pairing

ConradIrwin avatar Sep 04 '24 18:09 ConradIrwin

Closing for now, but offer to pair still stands.

ConradIrwin avatar Sep 19 '24 00:09 ConradIrwin

Sorry, I've been quite busy and missed your reply! I'd like to fix this but currently don't have the time. Feel free to use the code in this branch if it helps.

apricotbucket28 avatar Sep 19 '24 01:09 apricotbucket28