Skip to content

Add DocumentMode groundwork with MaskMode and Q toggle#4001

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

Add DocumentMode groundwork with MaskMode and Q toggle#4001
krVatsal wants to merge 8 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.

Comment thread editor/src/messages/portfolio/document/document_message_handler.rs
Comment thread editor/src/messages/portfolio/document/utility_types/misc.rs Outdated
@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.

Comment thread editor/src/messages/portfolio/document/document_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/document_message_handler.rs Outdated
Comment thread editor/src/messages/portfolio/document/document_message_handler.rs Outdated
@krVatsal krVatsal force-pushed the documentMode-extension branch from b14dbd9 to cbb615e Compare April 15, 2026 06:23
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.

2 issues found across 3 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/graph_operation/graph_operation_message_handler.rs">

<violation number="1" location="editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs:447">
P2: `ApplyMaskStencil` uses `ClipModeToggle`, making mask application state-dependent and capable of un-clipping already clipped target layers.</violation>
</file>

<file name="editor/src/messages/portfolio/document/document_message_handler.rs">

<violation number="1" location="editor/src/messages/portfolio/document/document_message_handler.rs:1194">
P1: ExitMaskMode uses a placeholder mask image and deletes the mask group, so user-drawn mask content is not applied.</violation>
</file>

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

Comment thread editor/src/messages/portfolio/document/document_message_handler.rs Outdated

// For each target layer, toggle clip mode so the existing clip infrastructure is engaged.
for layer in layers {
responses.add(GraphOperationMessage::ClipModeToggle { layer });
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: ApplyMaskStencil uses ClipModeToggle, making mask application state-dependent and capable of un-clipping already clipped target layers.

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/graph_operation/graph_operation_message_handler.rs, line 447:

<comment>`ApplyMaskStencil` uses `ClipModeToggle`, making mask application state-dependent and capable of un-clipping already clipped target layers.</comment>

<file context>
@@ -439,6 +439,17 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
+
+				// For each target layer, toggle clip mode so the existing clip infrastructure is engaged.
+				for layer in layers {
+					responses.add(GraphOperationMessage::ClipModeToggle { layer });
+				}
+				responses.add(NodeGraphMessage::RunDocumentGraph);
</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