Skip to content

Add DocumentMode groundwork with MaskMode and Q toggle#4001

Open
krVatsal wants to merge 7 commits intoGraphiteEditor:masterfrom
krVatsal:documentMode-extension
Open

Add DocumentMode groundwork with MaskMode and Q toggle#4001
krVatsal wants to merge 7 commits intoGraphiteEditor:masterfrom
krVatsal:documentMode-extension

Conversation

@krVatsal
Copy link
Copy Markdown
Contributor

@krVatsal krVatsal commented Apr 3, 2026

This PR implements the early groundwork for Document Mode as planned for community bonding / week 1 in Marquee Selection Masking.
It introduces MaskMode and wires a keyboard toggle, while intentionally avoiding rendering or visual feature work.

What this PR changes?

  • Re-enables DocumentMode enum and adds MaskMode
  • Stores current document_mode in editor state
  • Adds ToggleDocumentMode message
  • Handles toggle logic in document message handler:
  1. DesignMode -> MaskMode
    
  2. MaskMode -> DesignMode
    
  • Maps Q to ToggleDocumentMode

Scope and intent

  • Pure editor state change only
  • No rendering pipeline changes
  • No frontend UI additions
  • No behavior beyond mode state toggle

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new DocumentMode enum, including a MaskMode variant, and integrates it into the DocumentMessageHandler to allow toggling and setting the document mode. The review feedback suggests ensuring UI consistency by triggering PortfolioMessage::UpdateDocumentWidgets when the mode changes and recommends uncommenting and updating the fmt::Display implementation for DocumentMode to avoid leaving dead code.

@krVatsal krVatsal force-pushed the documentMode-extension branch from ca57043 to 268ec73 Compare April 9, 2026 08:59
@krVatsal
Copy link
Copy Markdown
Contributor Author

I wanted to continue with the work on part of my proposed changes but that needs these changes, should i continue adding further commits to this PR only? It would be great if you review this and then i can follow up with further changes for marquee selection. @Keavon

@Keavon
Copy link
Copy Markdown
Member

Keavon commented Apr 12, 2026

These changes comprise a relatively small change set, so you can and should continue adding functionality since this is so far just the user's entry point to a not-yet-built feature.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

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

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="editor/src/messages/portfolio/document/document_message_handler.rs">

<violation number="1" location="editor/src/messages/portfolio/document/document_message_handler.rs:1161">
P1: Mask group creation can self-parent because parent resolution happens after entering MaskMode and storing the same mask group ID used for the new layer.</violation>

<violation number="2" location="editor/src/messages/portfolio/document/document_message_handler.rs:1192">
P1: Applying mask on `ExitMaskMode` mutates the graph without transaction boundaries, unlike the discard branch, causing inconsistent undo/history behavior.</violation>

<violation number="3" location="editor/src/messages/portfolio/document/document_message_handler.rs:1194">
P1: Mask apply path discards authored mask content by using a placeholder 1x1 white image and then deleting the mask group.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

} else {
// Rasterize the mask group and apply it to target layers
if let Some(mask_group_id) = self.mask_group_id {
responses.add(GraphOperationMessage::ApplyMaskStencil {
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.

P1: Applying mask on ExitMaskMode mutates the graph without transaction boundaries, unlike the discard branch, causing inconsistent undo/history behavior.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/portfolio/document/document_message_handler.rs, line 1192:

<comment>Applying mask on `ExitMaskMode` mutates the graph without transaction boundaries, unlike the discard branch, causing inconsistent undo/history behavior.</comment>

<file context>
@@ -1133,16 +1142,69 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
+				} else {
+					// Rasterize the mask group and apply it to target layers
+					if let Some(mask_group_id) = self.mask_group_id {
+						responses.add(GraphOperationMessage::ApplyMaskStencil {
+							layers: self.mask_target_layers.clone(),
+							mask_image: graphene_std::raster::Image::new(1, 1, graphene_std::Color::WHITE),
</file context>

if let Some(mask_group_id) = self.mask_group_id {
responses.add(GraphOperationMessage::ApplyMaskStencil {
layers: self.mask_target_layers.clone(),
mask_image: graphene_std::raster::Image::new(1, 1, graphene_std::Color::WHITE),
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.

P1: Mask apply path discards authored mask content by using a placeholder 1x1 white image and then deleting the mask group.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/portfolio/document/document_message_handler.rs, line 1194:

<comment>Mask apply path discards authored mask content by using a placeholder 1x1 white image and then deleting the mask group.</comment>

<file context>
@@ -1133,16 +1142,69 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
+					if let Some(mask_group_id) = self.mask_group_id {
+						responses.add(GraphOperationMessage::ApplyMaskStencil {
+							layers: self.mask_target_layers.clone(),
+							mask_image: graphene_std::raster::Image::new(1, 1, graphene_std::Color::WHITE),
+						});
+						responses.add(NodeGraphMessage::DeleteNodes {
</file context>

responses.add(DocumentMessage::AddTransaction);

// Create the mask group layer as an empty custom layer container
graph_modification_utils::new_custom(mask_group_id, Vec::new(), self.new_layer_parent(true), responses);
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.

P1: Mask group creation can self-parent because parent resolution happens after entering MaskMode and storing the same mask group ID used for the new layer.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/portfolio/document/document_message_handler.rs, line 1161:

<comment>Mask group creation can self-parent because parent resolution happens after entering MaskMode and storing the same mask group ID used for the new layer.</comment>

<file context>
@@ -1133,16 +1142,69 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
+				responses.add(DocumentMessage::AddTransaction);
+
+				// Create the mask group layer as an empty custom layer container
+				graph_modification_utils::new_custom(mask_group_id, Vec::new(), self.new_layer_parent(true), responses);
+
+				// Set the mask group opacity to 50% so the user can see artwork beneath
</file context>

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.

2 participants