Skip to content

fix: cut and copy do something, and reach other applications - #79

Merged
IAmJSD merged 2 commits into
mainfrom
t3code/fix-marquee-cut-copy-1
Aug 30, 2026
Merged

IAmJSD merged 2 commits into
mainfrom
t3code/fix-marquee-cut-copy-1

Conversation

@IAmJSD

@IAmJSD IAmJSD commented Aug 30, 2026

Copy link
Copy Markdown
Member

Reported as "cut and copy on a marquee seem broken". Two separate faults, plus one in the gpui fork.

Copy and cut were silent no-ops after an undo

The marquee itself is fine — it commits the selection correctly, and copy_pixels clips to it correctly. What breaks them is losing the active layer:

  • undoing a layer insert (Document::apply_op, LayerInsert/Undo)
  • redoing a layer removal (LayerRemove/Redo)
  • EditBuilder::remove_layer, i.e. Delete Layer

all set active_layer to None and left it there. So marquee → copy → paste → undo → cut left the document with no active layer, copy_pixels returned None at its first line, copy silently kept the previous clipboard and cut did nothing — while the status bar reported "Copy"/"Cut" as though they had run. Reproduced in the running app: after the undo no layer row is selected, and Ctrl+X adds no history entry and clears no pixels.

LayerTree::neighbour_of now names the replacement — the sibling below the hole, the layer that fell into it if the hole was at the bottom, or the enclosing group once it is empty — and Document::reselect_after_removal applies it at all three sites, pruning selected as it goes. That is Photoshop's rule: deleting a layer selects the one below it, never nothing.

Copy, Copy Merged and Cut now refuse with "Select a pixel layer to copy from" when there is genuinely nothing to copy (an adjustment or text layer active), instead of reporting success.

Copying never reached the system clipboard at all

sync_clipboard_out looked the exporter up with c.id() == "png". Every codec registers as codec.<format>, so the lookup never matched and the function returned before touching the system clipboard — on every platform. The slice/artboard PNG export had the same wrong id and was dead in the same way. Both now go through one png_codec() keyed on PNG_CODEC_ID.

The other half of that was in gpui: both Linux backends serialised a clipboard item as item.text().unwrap_or_default(), so an image went out as an empty string. Fixed in the fork (IAmJSD/gpui@4ab83c7, "Put images on the Linux clipboards, not an empty string") and the pin moves to it.

Tests

  • removing_the_active_layer_selects_a_neighbour, removing_the_only_layer_falls_back_to_its_group (crates/core)
  • undoing_a_paste_leaves_a_layer_active plus refusal coverage (plugins/commands-core)
  • the_png_codec_answers_to_the_id_it_is_looked_up_by (crates/app)
  • cargo test --workspace green.

Verified in the app under Xvfb: after the undo the Background is active again and Ctrl+X clears the marquee region; and with a standalone x11rb requestor, a copied marquee leaves TARGETS: TARGETS SAVE_TARGETS image/png on the CLIPBOARD and hands over a 100×80 PNG of the region.

🤖 Generated with Claude Code

IAmJSD and others added 2 commits August 30, 2026 04:50
Copy and cut on a marquee were silent no-ops in the most ordinary
sequence there is: marquee, copy, paste, undo, cut. Undoing the paste
removed the pasted layer and set `active_layer` to None, nothing put it
anywhere else, and `copy_pixels` starts by resolving the active layer --
so copy quietly kept whatever was on the clipboard before and cut did
nothing at all, while the status line reported "Copy" and "Cut" as if
they had run. Deleting a layer left the document in the same state.

Removals now pick a neighbour the way Photoshop does: the layer below the
one that left, the one that fell into its place if it was at the bottom,
or the group that held it once that group holds nothing else. All three
removal paths -- delete, undo of an insert, redo of a remove -- go
through it, so there is no way back to a document with layers and no
active one. Copy, Copy Merged and Cut also say "Select a pixel layer to
copy from" when there is genuinely nothing to copy, rather than
reporting success.

Copying out of Schist reached no other application either, for a
different reason: `sync_clipboard_out` looked the exporter up by the id
"png", every codec is registered as `codec.<format>`, so the lookup
never matched and the function returned before touching the system
clipboard. Exporting slices and artboards had the same wrong id and was
dead in the same way. Both now share one `png_codec()` on the constant,
with a test that the codec plugin registers under it.

The other half of that was in gpui, which serialised a clipboard item as
its text and nothing else, so an image went out as an empty string; the
fork pin moves to the commit that offers each entry in its own format.
Copying a marquee now leaves a PNG of the region on the X11 CLIPBOARD,
which `xclip -t image/png -o` and every other application can read.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@IAmJSD
IAmJSD merged commit 569c19c into main Aug 30, 2026
3 checks passed
@IAmJSD
IAmJSD deleted the t3code/fix-marquee-cut-copy-1 branch August 30, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant