Skip to content

Conversation

@theaniketgiri
Copy link

@theaniketgiri theaniketgiri commented Jan 2, 2026

Part of #2740

This PR addresses the "Match statements" section of the tracking issue by extracting three large match arms from process_message() into dedicated helper methods.

Changes

Extracted the following helper methods in DocumentMessageHandler:

Method Lines Extracted Purpose
handle_group_selected_layers ~50 lines Handles layer grouping in both artboard and non-artboard workflows
handle_move_selected_layers_to ~85 lines Handles layer movement with proper transform preservation
handle_nudge_selected_layers ~75 lines Handles keyboard nudging with optional resize mode

Benefits

  • Improved readability: The main match statement is now ~210 lines shorter
  • Better maintainability: Each operation is now self-contained in its own method
  • Easier testing: Helper methods can potentially be unit tested independently
  • Clearer intent: Method names describe what the code does

Before/After

Before:

DocumentMessage::GroupSelectedLayers { group_folder_type } => {
    // ~50 lines of inline code
}

After:

DocumentMessage::GroupSelectedLayers { group_folder_type } => {
    self.handle_group_selected_layers(group_folder_type, responses);
}

Testing

  • Verified compilation with cargo check
  • Logic and behavior remain unchanged - this is a pure refactor
  • Existing tests pass (note: SIGSEGV in tests is a pre-existing issue on master)

@timon-schelling timon-schelling marked this pull request as draft January 2, 2026 14:25
@timon-schelling
Copy link
Member

Why the new workflow? That seems unrelated.

Converted to draft because this not ready for review.

Part of GraphiteEditor#2740 - Code quality refactors.

This commit addresses the 'Match statements' section of the tracking
issue by extracting three large match arms from process_message() into
dedicated helper methods:

- handle_group_selected_layers: Handles layer grouping in both artboard
  and non-artboard workflows (~50 lines extracted)
- handle_move_selected_layers_to: Handles layer movement with proper
  transform preservation (~85 lines extracted)
- handle_nudge_selected_layers: Handles keyboard nudging with optional
  resize mode (~75 lines extracted)

The main match statement in DocumentMessageHandler is now ~210 lines
shorter and more readable. Logic and behavior remain unchanged.
@theaniketgiri theaniketgiri force-pushed the issue/2740-code-quality-refactors branch from 50bf1ad to dd65498 Compare January 2, 2026 14:31
@theaniketgiri
Copy link
Author

Why the new workflow? That seems unrelated.

Converted to draft because this not ready for review.

Hi @timon-schelling, thanks for the review!

You're absolutely right - both the workflow file and pnpm-lock were accidentally included. They were from a different branch I was working on and got mixed in when I created this PR.

I've fixed this now:

Rebased onto master
Removed the unrelated workflow file and pnpm-lock
The PR now only contains the refactoring changes

@theaniketgiri theaniketgiri marked this pull request as ready for review January 2, 2026 14:37
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