8000 reorder_layer: don't mark the image changed when the layer doesn't move (#136) by tomerkon · Pull Request #189 · gimp-mcp/gimp-mcp · GitHub
[go: up one dir, main page]

Skip to content

reorder_layer: don't mark the image changed when the layer doesn't move (#136) - #189

Merged
tomerkon merged 1 commit into
mainfrom
reorder-layer-noop
Dec 3, 2026
Merged

tomerkon merged 1 commit into
mainfrom
reorder-layer-noop

Conversation

@tomerkon
@tomerkon tomerkon commented Dec 3, 2026 •
Copy link
Copy Markdown
Collaborator

Fixes #136.

Problem

reorder_layer marked the image as changed (unsaved-changes marker) even when the layer didn't move. GIMP's reorder_item dirties the image whenever it's called, also when the layer stays where it is. Checked live on GIMP 3.2.8: every no-op dirtied the image, for top-level layers, grouped layers, a floating selection, and positions GIMP clamps (-1 for the top layer, 99 for the bottom one).

Change

_reorder_layer works out where GIMP would put the layer: new_position clamped to the layer's siblings (negative = top, past the end = bottom), counting the siblings in the layer's own group for a grouped layer (since #169). If that is image.get_item_position(layer), it returns success without calling reorder_item. Real moves, and moves GIMP refuses, behave as before.

The tool's description already documents the clamping, so it is unchanged. CHANGELOG entry under [Unreleased] / Fixed. No result or parameter changes, so a patch-level fix.

Tests

  • tests/test_reorder_layer.py (new, offline): no-op at each position, clamped no-ops, the only layer, real moves (including clamped ones), a grouped layer counting its group's siblings, and a refused move still failing. Fails 13 subtests on main, passes here.
  • tests/test_grouped_layers_live.py: 10 no-op moves (grouped, nested, only child, top-level, clamped) must leave the tree unchanged and the image clean. Fails with main's plugin, passes with this one, on GIMP 3.2.8 (snap).
  • test_layer_position_checks_live.py and test_negative_index_live.py still pass live; uvx ruff@0.15.11 check and all offline tests pass.

Not checked

The comment on #136 asked whether a no-op also cleared the redo history (as an empty undo group does, #148). Plug-ins can't undo or redo on 3.2 (#86), so it wasn't checked; with this change a no-op never reaches GIMP, so it no longer matters here.

Summary by CodeRabbit

  • Bug Fixes
    • Reordering a layer to its current position no longer marks the image as changed, including when the requested position is clamped to that position.
    • Actual layer moves continue to be applied within the same group.

…ve (#136)

GIMP's reorder_item marks the image as changed even when the layer stays
where it is. Work out where GIMP would put the layer (new_position clamped
to its siblings: negative = top, past the end = bottom, counting the layer's
group for a grouped layer) and return success without calling reorder_item
when that is its current position.
@github-actions github-actions Bot added bug Something isn't working documentation Improvements or additions to documentation labels Dec 3, 2026
@coderabbitai
coderabbitai Bot commented Dec 3, 2026 •
Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

reorder_layer now skips the reorder operation when the requested position, after clamping to the layer’s sibling range, matches its current position. Tests cover unchanged and moved layers, including grouped layers and clamped positions.

Changes

Layer reorder no-op

Layer / File(s) Summary
Skip unchanged reorder requests
gimp-mcp-plugin.py, tests/test_reorder_layer.py, tests/test_grouped_layers_live.py, CHANGELOG.md
_reorder_layer returns success without calling reorder_item when the clamped destination matches the current sibling position. Tests cover no-op requests, actual moves, grouped layers, and refused moves. The changelog documents the no-op behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Possibly related PRs

  • gimp-mcp/gimp-mcp#134: Checks the reorder result and reports refused moves, which this change also tests.
  • gimp-mcp/gimp-mcp#169: Moves layers within their source group, whose sibling-relative position is used by this change.

Suggested labels: bug

Suggested reviewers: iyuzhang

Merge Risk: Minimal · up to 6132e

This change stops no-op layer reorders from marking the image as changed. Moves that actually change a layer's position behave as before, so the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: reorder_layer no longer marks the image as changed when the layer does not move. The raw summary and PR objectives both describe a no-op guard in _reorder_layer that s…
Linked Issues check Passed [#136] Requires _reorder_layer to compute the effective destination, clamped to the sibling range (negative means top, past the end means bottom), and to return success without calling `reorder_item…
Out of Scope Changes check Passed The changed files are gimp-mcp-plugin.py (the _reorder_layer no-op check), CHANGELOG.md (an [Unreleased] / Fixed entry for this bug), and the tests tests/test_reorder_layer.py and `tests/tes…
Full details: Title check

Explanation

The title names the main change: reorder_layer no longer marks the image as changed when the layer does not move. The raw summary and PR objectives both describe a no-op guard in _reorder_layer that skips image.reorder_item when the clamped destination equals the current position. The title is specific and matches the changeset. The number (#136) refers to the linked issue, while the PR objectives cite #189 as the PR number; this mismatch does not affect the content match.

Full details: Linked Issues check

Explanation

[#136] Requires _reorder_layer to compute the effective destination, clamped to the sibling range (negative means top, past the end means bottom), and to return success without calling reorder_item when that destination equals image.get_item_position(layer). The PR description and the AI-generated summary of gimp-mcp-plugin.py both state this behavior. The summary says the grouped case counts siblings in the layer's own parent group, which matches the related-context requirement from #131. tests/test_reorder_layer.py asserts the no-op cases (each position, clamped positions, sole layer, grouped layer) with reorder_item not called, and the real-move cases with reorder_item called. tests/test_grouped_layers_live.py covers 10 live no-op cases. Limitation: the plugin source blob could not be read in this review (the diff read failed and the file read was truncated), so the code-level verdict rests on the summary and the test assertions. Refused moves are still reported as errors, per test_a_refused_move_is_still_an_error.

Full details: Out of Scope Changes check

Explanation

The changed files are gimp-mcp-plugin.py (the _reorder_layer no-op check), CHANGELOG.md (an [Unreleased] / Fixed entry for this bug), and the tests tests/test_reorder_layer.py and tests/test_grouped_layers_live.py. All of them relate to #136. The summary reports no changes to exported declarations, tool descriptions, or parameters. The plugin source itself could not be read directly in this review, so this verdict relies on the summary and the test file.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 5cdb39f and 6132e1f.

Files selected for processing: 4

  • CHANGELOG.md
  • gimp-mcp-plugin.py
  • tests/test_grouped_layers_live.py
  • tests/test_reorder_layer.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@tomerkon
tomerkon merged commit 4f4b862 into main Dec 3, 2026
6 checks passed
@tomerkon
tomerkon deleted the reorder-layer-noop branch December 3, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reorder_layer marks the image as changed when the layer doesn't move

1 participant

0