Repository navigation
fix: cut and copy do something, and reach other applications - #79
Merged
Merged
Conversation
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]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_pixelsclips to it correctly. What breaks them is losing the active layer:Document::apply_op,LayerInsert/Undo)LayerRemove/Redo)EditBuilder::remove_layer, i.e. Delete Layerall set
active_layertoNoneand left it there. So marquee → copy → paste → undo → cut left the document with no active layer,copy_pixelsreturnedNoneat 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_ofnow 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 — andDocument::reselect_after_removalapplies it at all three sites, pruningselectedas 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_outlooked the exporter up withc.id() == "png". Every codec registers ascodec.<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 onepng_codec()keyed onPNG_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_activeplus refusal coverage (plugins/commands-core)the_png_codec_answers_to_the_id_it_is_looked_up_by(crates/app)cargo test --workspacegreen.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/pngon the CLIPBOARD and hands over a 100×80 PNG of the region.🤖 Generated with Claude Code