Skip to content

Add cross-application copy-paste by also copying layers to the clipboard as SVG - #4499

Merged
timon-schelling merged 57 commits into
GraphiteEditor:masterfrom
VimYoung:clipboard-svg-fix
Nov 11, 2026
Merged

timon-schelling merged 57 commits into
GraphiteEditor:masterfrom
VimYoung:clipboard-svg-fix

Conversation

@VimYoung

@VimYoung VimYoung commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR aims to resolve #2373. Solution's approach has been thoroughly discussed in discord's development channel. The PR will fix this issue by introducing copy of both text and svg+xml mime types when copying a selection to the clipboard. Essentially making it possible for other apps to take the svg representation while graphite picks up the internal json representation for copy pasting.

Notes

  1. As mentioned by hypercube, image/svg+xml is not supported by firefox and safari Stable so that is handled.
  2. The intersecting by desktop still doesn't copy the svg and simply ignores it.

Following example showcase the same copy paste not working across apps (krita and inkscape shown as the other apps) in current build vs it working in this branch while still being compatible across graphite tabs.

Before(Only across graphite tabs, not across apps):

editor_before.mp4

After(Across tabs and other apps):

editor_after.mp4

@VimYoung
VimYoung marked this pull request as ready for review September 6, 2026 10:12

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread frontend/src/managers/clipboard.ts Resolved
Comment thread editor/src/node_graph_executor.rs Resolved

@0HyperCube 0HyperCube left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well; thanks for your work so far.

Comment thread editor/src/node_graph_executor.rs Resolved
Comment thread frontend/src/managers/clipboard.ts Resolved
@timon-schelling

Copy link
Copy Markdown
Member

I would like to wait with this until winit update is merged. And we might want to make this API lazy.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 11 files (changes from recent commits).

Confidence score: 3/5

  • In editor/src/node_graph_executor/runtime.rs, a copy request coalesced with graph evaluation can read monitor nodes before execution refreshes them, leaving the clipboard with stale or empty SVG. Ensure the copy reads the refreshed monitor output.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/node_graph_executor/runtime.rs">

<violation number="1" location="editor/src/node_graph_executor/runtime.rs:203">
P2: When a copy request and a graph evaluation are coalesced in one runtime pass, this line introspects monitor nodes before the pending execution refreshes them, so the clipboard can contain stale or empty SVG. Ensure the copy path reads output from the relevant completed execution, and avoid relying only on request reordering because the execution branch currently returns before later requests.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread editor/src/node_graph_executor.rs Resolved
}

let requests = [preferences, graph, eyedropper, execution].into_iter().flatten();
let requests = [preferences, graph, eyedropper, svg_clipboard, execution].into_iter().flatten();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When a copy request and a graph evaluation are coalesced in one runtime pass, this line introspects monitor nodes before the pending execution refreshes them, so the clipboard can contain stale or empty SVG. Ensure the copy path reads output from the relevant completed execution, and avoid relying only on request reordering because the execution branch currently returns before later requests.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/node_graph_executor/runtime.rs, line 203:

<comment>When a copy request and a graph evaluation are coalesced in one runtime pass, this line introspects monitor nodes before the pending execution refreshes them, so the clipboard can contain stale or empty SVG. Ensure the copy path reads output from the relevant completed execution, and avoid relying only on request reordering because the execution branch currently returns before later requests.</comment>

<file context>
@@ -200,7 +200,7 @@ impl NodeRuntime {
 		}
 
-		let requests = [preferences, graph, eyedropper, execution, svg_clipboard].into_iter().flatten();
+		let requests = [preferences, graph, eyedropper, svg_clipboard, execution].into_iter().flatten();
 
 		for request in requests {
</file context>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically true however it probably isn't very relevant since the user would be copying an SVG that is not yet rendered into the viewport.

You could fix this by having a result variable instead of an early return:

let mut result = None;
for request in requests {
	match request {
		// ...
		GraphRuntimeRequest::ExecutionRequest(ExecutionRequest { execution_id, mut render_config, .. }) => {
			// ...
			result = Some(texture);
		}
	}
}
result

@VimYoung

VimYoung commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Hey @timon-schelling , we can wait for the API to be merged and then do the changes, what do you mean for the API to be lazy here?
Also can you assign the issue to me as this PR is opened and in review?

@timon-schelling

Copy link
Copy Markdown
Member

Hey @timon-schelling , we can wait for the API to be merged and then do the changes, what do you mean for the API to be lazy here?

See the top level API definitions in rust-windowing/winit#4658

Both the DnD and Clipboard APIs are lazy in winit, meaning data only needs to be constructed once the other application accepts (based on data type).

I think we should model it in a similar way.
I'm not completely decided on how to model this with messages though.

Also can you assign the issue to me as this PR is opened and in review?

We usually do that when something is merged.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 8 files (changes from recent commits).

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.
Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

}

let requests = [preferences, graph, eyedropper, execution].into_iter().flatten();
let requests = [preferences, graph, eyedropper, svg_clipboard, execution].into_iter().flatten();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically true however it probably isn't very relevant since the user would be copying an SVG that is not yet rendered into the viewport.

You could fix this by having a result variable instead of an early return:

let mut result = None;
for request in requests {
	match request {
		// ...
		GraphRuntimeRequest::ExecutionRequest(ExecutionRequest { execution_id, mut render_config, .. }) => {
			// ...
			result = Some(texture);
		}
	}
}
result

VimYoung and others added 2 commits September 17, 2026 17:05
…ditor#4518)

* Switch Color struct back to storing unassociated alpha

* Address review feedback

* Update the Invert node and legacy image migration for straight alpha and add round-trip tests

---------

Co-authored-by: Keavon Chambers <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 119 files (changes from recent commits).

Not reviewed (too large): node-graph/nodes/raster/src/adjustments.rs (~2,305 lines) - if these are generated or fixture files, add them to ignored paths to exclude them from future reviews.

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

@VimYoung

Copy link
Copy Markdown
Contributor Author

Hey @0HyperCube, I have done the changes that you proposed after the second review, please take a look if this PR is still relevant (as there were some ongoing discussions on scrapping it it favor of something that would follow winit's new API changes).

@0HyperCube

Copy link
Copy Markdown
Contributor

Hi @VimYoung, thanks for your continued work on this. In my view this is the most viable approach for the moment.

The winit clipboard support with other types was added in #4519 (graphite now uses a winit fork). It should now be possible to implement the desktop support to this PR. See the clipboard example.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files (changes from recent commits).

Confidence score: 5/5

  • desktop/wrapper/src/intercept_frontend_message.rs: The only flagged issue is PR-title convention enforcement; it does not indicate a code or user-facing regression. Rename the title to use an imperative leading verb, such as Add cross-application..., to satisfy the documented format.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="desktop/wrapper/src/intercept_frontend_message.rs">

<violation number="1" location="desktop/wrapper/src/intercept_frontend_message.rs:119">
P2: Custom agent: **PR title enforcement**

The PR title does not use an imperative leading verb: `Clipboard` is a noun, and `Clipboard:` is not one of the documented subsystem prefixes. Rename it to `Add cross-application copy-paste support`.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

@VimYoung

Copy link
Copy Markdown
Contributor Author

I have pushed a base commit to propagate the svg_string over to app.rs where it is being part of the clipboard's "single source of truth" and provided if an image of extension svg is asked.
The TypeHint enum doesn't have an xml type variant so I thought image with svg would be the best alternative.

Also I don't have tests and a desktop version of graphite in dev to ensure if this is the case and the final copy paste is even working in desktop mode or not(I would need reviewer's guidance).

From the dnd.rs example I figured Image data needs to be passed as vector of bytes(ref).

@0HyperCube 0HyperCube left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the desktop support. It seems to be working well from my testing.

Also I don't have […] a desktop version of graphite in dev

To run the desktop, use cargo run -- desktop from the graphite/ directory. To see all options for the cargo-run tool, use cargo run -- --help.

I don't have tests

To add an automated testing, which would also be desirable, you can add to copy_layers_to_clipboard by asserting that a suitable SVG is also copied. You can run this using cargo test -p graphite-editor copy_layers_to_clipboard.

I figured Image data needs to be passed as vector of bytes

For PNG data which cannot necessarily be represented as an UTF8 string, bytes are required. However since the SVGs will always be UTF8 you can just use the SendData::String if you prefer (however both approaches work fine).

The TypeHint enum doesn't have an xml type variant so I thought image with svg would be the best alternative.

The TypeHint::Image { extension_hint: Some("svg") } is the right choice since that is recognised by x11 and wayland.

@VimYoung

VimYoung commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

To add an automated testing, which would also be desirable, you can add to copy_layers_to_clipboard by asserting that a suitable SVG is also copied.

Since the signature of this method only returns String (graphite json) , Should I change it to return a combo of both svg and json and then add a new test function using it??

But technically the svg is never used internally by graphite as it sticks to it's own internal structure , so I will just try to assert it for now.

@0HyperCube

Copy link
Copy Markdown
Contributor

Since the signature of this method only returns String (graphite json) , Should I change it to return a combo of both svg and json and then add a new test function using it??

If you mean the copy_layers_to_clipboard utility function in the test module, then it would be reasonable to adjust to send back all copied data.

@VimYoung

VimYoung commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

I just had time to adjust the function signature of copy_layers_to_clipboard to send svg back. Now the clipboard tests check the sanity(being valid xml start and end) and presence (being not None) of SVG. @timon-schelling @TrueDoctor @0HyperCube . Please see the changes, I guess the PR is ready.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 15 files (changes from recent commits).

Confidence score: 3/5

  • In thumbnails.rs, gradient transforms use the non-thumbnail path even though the SVG viewBox already uses bounds coordinates, which can misrender gradients. Set thumbnail: true for this render.
  • In thumbnails.rs, infinite graphical layers are dropped when calculating SVG bounds, so color or gradient selections may produce no SVG or disappear from mixed selections. Handle RenderBoundingBox::Infinite with appropriate bounds.
  • In thumbnails.rs, layers render in NodeId order rather than document z-order, so overlapping reordered layers can appear incorrectly after cross-application paste. Render them in document structure order.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/node_graph_executor/runtime/thumbnails.rs">

<violation number="1" location="editor/src/node_graph_executor/runtime/thumbnails.rs:379">
P2: Infinite graphical layers are discarded when calculating the SVG bounds, so color or gradient layers can produce no SVG or be omitted from a mixed selection. Handle `RenderBoundingBox::Infinite` with an appropriate finite copy area.</violation>

<violation number="2" location="editor/src/node_graph_executor/runtime/thumbnails.rs:385">
P2: This render uses the non-thumbnail gradient path, so `Footprint::from_bounds(bounds, ...)` is applied to gradient transforms even though the SVG viewBox already uses `bounds` coordinates. Set `thumbnail: true` here, matching `render_svg`, so gradients are clipped to the copied bounds without applying the bounds translation twice.</violation>

<violation number="3" location="editor/src/node_graph_executor/runtime/thumbnails.rs:388">
P2: The SVG preserves NodeId-sorted selection order rather than document z-order, so overlapping reordered layers can render incorrectly after cross-application paste. Render layers in document structure order.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

..Default::default()
};
let mut render = SvgRender::new();
for content in &contents {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The SVG preserves NodeId-sorted selection order rather than document z-order, so overlapping reordered layers can render incorrectly after cross-application paste. Render layers in document structure order.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At editor/src/node_graph_executor/runtime/thumbnails.rs, line 388:

<comment>The SVG preserves NodeId-sorted selection order rather than document z-order, so overlapping reordered layers can render incorrectly after cross-application paste. Render layers in document structure order.</comment>

<file context>
@@ -344,24 +344,55 @@ impl ThumbnailContent {
+		..Default::default()
+	};
+	let mut render = SvgRender::new();
+	for content in &contents {
+		content.graphic().render_svg(&mut render, &render_params);
+	}
</file context>

.iter()
.filter_map(|content| match content.content_bounds() {
RenderBoundingBox::Rectangle(bounds) if (bounds[1] - bounds[0]) != DVec2::ZERO => Some(bounds),
_ => None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Infinite graphical layers are discarded when calculating the SVG bounds, so color or gradient layers can produce no SVG or be omitted from a mixed selection. Handle RenderBoundingBox::Infinite with an appropriate finite copy area.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At editor/src/node_graph_executor/runtime/thumbnails.rs, line 379:

<comment>Infinite graphical layers are discarded when calculating the SVG bounds, so color or gradient layers can produce no SVG or be omitted from a mixed selection. Handle `RenderBoundingBox::Infinite` with an appropriate finite copy area.</comment>

<file context>
@@ -344,24 +344,55 @@ impl ThumbnailContent {
+		.iter()
+		.filter_map(|content| match content.content_bounds() {
+			RenderBoundingBox::Rectangle(bounds) if (bounds[1] - bounds[0]) != DVec2::ZERO => Some(bounds),
+			_ => None,
+		})
+		.reduce(|[min, max], [other_min, other_max]| [min.min(other_min), max.max(other_max)])?;
</file context>

@timon-schelling timon-schelling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TrueDoctor let me have another look before you merge, I remember having something I would want to change. (Currently not at my PC)

@TrueDoctor TrueDoctor changed the title Clipboard: Cross-application copy-paste support Add cross-application copy-paste by also copying layers to the clipboard as SVG Nov 6, 2026
@timon-schelling
timon-schelling added this pull request to the merge queue Nov 11, 2026
Merged via the queue into GraphiteEditor:master with commit f11e2d7 Nov 11, 2026
14 checks passed
@VimYoung
VimYoung deleted the clipboard-svg-fix branch November 11, 2026 05:28
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.

Copy/pasting vector and raster content between other graphics apps

5 participants