Skip to content

Fix crop bug#71

Merged
AlanRockefeller merged 7 commits intomainfrom
test
Apr 12, 2026
Merged

Fix crop bug#71
AlanRockefeller merged 7 commits intomainfrom
test

Conversation

@AlanRockefeller
Copy link
Copy Markdown
Owner

@AlanRockefeller AlanRockefeller commented Apr 12, 2026

Summary by CodeRabbit

  • New Features

    • Added "edited" status tracking in thumbnail coverage visualization, now displaying four distinct image states (uploaded, edited, stacked, to-do).
    • Enhanced crop interaction with image source freezing and zoom/pan locking during cropping for improved stability.
  • Improvements

    • Improved metadata handling for saved images.
    • Updated thumbnail tile appearance with folder-specific coloring.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

Walkthrough

Changes across the codebase restructure post-save workflows with index-preservation logic, introduce sidecar metadata updates marking images as edited, enhance crop-drag UI stability through image source freezing and zoom/pan locking, refactor thumbnail rendering for folder items, and extend coverage statistics to track an "edited" image bucket alongside existing upload/stack/todo metrics.

Changes

Cohort / File(s) Summary
Save & Metadata Flow
faststack/app.py, faststack/io/sidecar.py
Reordered post-save operations to snapshot image paths, update sidecar metadata (edited=True), refresh image lists, and preserve index state; added new SidecarManager.update_metadata() method for conditional metadata field updates.
Crop Interaction UI
faststack/qml/Components.qml
Introduced crop-drag guards that freeze displayed image source and lock zoom/pan transforms; refactored crop start/interaction flow with new freezeCropImageSource(), releaseCropImageSource(), and interaction lifecycle functions; added deferred geometry updates during active crop drags.
Thumbnail & Folder Display
faststack/qml/ThumbnailTile.qml, faststack/thumbnail_view/folder_stats.py
Updated thumbnail tile background color logic and folder-specific rendering; redesigned coverage sparkline from 3-lane to 4-lane layout (adding "edited" bucket); extended FolderStats.coverage_buckets to track 4-tuples with edited-image metrics and case-insensitive metadata lookup support.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • PR #54 — Directly modifies sidecar metadata API and key-based storage; overlaps with new update_metadata() method and edited-metadata flows
  • PR #21 — Alters crop interaction and image source behavior in Components.qml; overlaps with crop freezing/locking and interaction lifecycle changes
  • PR #70 — Modifies ThumbnailTile.qml thumbnail rendering, folder image handling, and coverage sparkline layout; direct overlap with tile refactoring
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix crop bug' is vague and does not convey meaningful details about the changeset. While it relates to cropping functionality mentioned in the changes, it lacks specificity about what aspect of the crop feature was fixed or what the actual bug was. Provide a more descriptive title that explains what specific crop bug was fixed, such as 'Freeze image source and lock zoom/pan during crop drag' or 'Fix crop drag coordinate system stability'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1f30ecc304

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread faststack/app.py
Comment on lines +2030 to +2031
if saved_path:
self.sidecar.update_metadata(saved_path, {"edited": True})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Write edited metadata to the save-origin sidecar

_on_save_finished now unconditionally calls self.sidecar.update_metadata(saved_path, {"edited": True}), but save_edited_image explicitly allows users to keep navigating while the background save runs, and _switch_to_directory replaces self.sidecar when folders change. If a save started in folder A finishes after the user moved to folder B, this line writes an absolute-key metadata entry into folder B’s faststack.json instead of updating folder A, which corrupts sidecar data and leaves the actual saved image unmarked in its own folder.

Useful? React with 👍 / 👎.

Comment on lines +22 to +23
readonly property bool isCropSourceFrozen: cropDragImageSource !== "" && ((mainMouseArea && mainMouseArea.isCropDragging) || (uiState && uiState.isCropping))
readonly property string displayedImageSource: isCropSourceFrozen ? cropDragImageSource : requestedImageSource
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Freeze crop source only while dragging

The new freeze condition keeps displayedImageSource pinned whenever uiState.isCropping is true, not just during drag. Because crop mode now snapshots cropDragImageSource on entry, mainImage.source stays stuck on that initial frame for the entire crop session, so later uiState.currentImageSource updates (for example high-res swaps after zooming) are ignored until crop mode exits. That causes stale previews during cropping and defeats the intended “freeze during gesture” behavior.

Useful? React with 👍 / 👎.

@AlanRockefeller
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@faststack/app.py`:
- Around line 2029-2031: The metadata update only sets {"edited": True} so
edited_date is missing and no previous metadata is captured for undo; change the
flow in the code that updates sidecar metadata (the block using
self.sidecar.update_metadata(saved_path, {"edited": True})) to: 1) read the
current metadata via self.sidecar.get_metadata(saved_path) into old_meta, 2)
create new_meta by merging old_meta with edited=True and a timestamp
(edited_date = now()), 3) call self.sidecar.update_metadata(saved_path,
new_meta), and 4) record the old_meta as an undoable operation via the app's
undo/backup mechanism (e.g., self.undo_manager.record_metadata_change or the
same backup routine used for image data) so operations like crop, auto_levels,
and auto_white_balance can fully revert metadata; apply the same change at the
other same-pattern sites (the blocks used by crop, auto_levels,
auto_white_balance).
- Around line 2055-2056: The code currently only logs unexpected save payloads
at the log.warning("Save finished with unexpected result shape: %r", result)
branch, which can leave the UI stuck on the "Saving..." indicator; update that
branch to not only log but also invoke the same completion/cleanup path used for
normal successes (e.g., call the success handler or emit the
save-complete/notify-save-done routine that clears the UI state and resets any
in-progress flags), ensuring the client is notified that the save finished even
when the payload shape is malformed.

In `@faststack/qml/Components.qml`:
- Around line 51-57: The onIsCroppingChanged handler currently only calls
loupeView.freezeCropImageSource() / releaseCropImageSource() and misses
unwinding the crop drag state and locks when uiState.isCropping becomes false;
update onIsCroppingChanged (the function that reacts to uiState.isCropping) so
that when uiState.isCropping flips to false it also ensures any ongoing crop
drag is terminated by calling the same cleanup used in the Escape/local flow
(e.g., invoke endCropInteraction() or equivalent), set uiState.isCropDragging =
false, and clear any zoom/pan locks so onReleased doesn’t skip cleanup and the
view is fully unlocked.
- Around line 658-664: beginNewCrop currently writes raw normalized coordinates
(mx,my) into uiState.currentCropBox and calls setCropBoxStart even when the
pointer is outside the image; clamp mx and my to the image bounds before using
them so values stay within [0,1000] (or your normalized range) — e.g. compute
clampedMx = Math.max(0, Math.min(1000, mx)) and clampedMy = Math.max(0,
Math.min(1000, my)), pass those to setCropBoxStart and store
Math.round(clampedMx), Math.round(clampedMy) in uiState.currentCropBox, while
still setting cropStartX/cropStartY from the original mouseX/mouseY.
- Around line 60-75: The escape handler can let a previously-armed
rotationThrottleTimer fire and reapply pendingRotation after you revert/cancel;
update Keys.onEscapePressed to cancel any queued rotation work by stopping
rotationThrottleTimer and clearing the pendingRotation value (or resetting it to
a neutral value) before calling
mainMouseArea.endCropInteraction()/controller.cancel_crop_mode() and resetting
cropRotation; reference rotationThrottleTimer, pendingRotation, mainMouseArea,
and the Keys.onEscapePressed block so the timer is stopped and pendingRotation
cleared in both the rotate-revert and cancel branches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4fa806cc-5801-4250-b694-6323f4bbee5c

📥 Commits

Reviewing files that changed from the base of the PR and between ebac1bf and ee7171f.

📒 Files selected for processing (6)
  • .codex
  • faststack/app.py
  • faststack/io/sidecar.py
  • faststack/qml/Components.qml
  • faststack/qml/ThumbnailTile.qml
  • faststack/thumbnail_view/folder_stats.py

Comment thread faststack/app.py
Comment on lines +2029 to +2031
# 1. Update sidecar metadata FIRST so all following refreshes see it
if saved_path:
self.sidecar.update_metadata(saved_path, {"edited": True})
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Persist the full edited metadata and make it undoable.

These writes only set edited=True. That leaves edited_date blank in the metadata UI, and the undoable flows here (crop, auto_levels, auto_white_balance) will still show the image as edited after the backup is restored because the previous metadata state is never captured/restored.

Also applies to: 7376-7377, 7621-7622, 7717-7718, 7866-7867

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@faststack/app.py` around lines 2029 - 2031, The metadata update only sets
{"edited": True} so edited_date is missing and no previous metadata is captured
for undo; change the flow in the code that updates sidecar metadata (the block
using self.sidecar.update_metadata(saved_path, {"edited": True})) to: 1) read
the current metadata via self.sidecar.get_metadata(saved_path) into old_meta, 2)
create new_meta by merging old_meta with edited=True and a timestamp
(edited_date = now()), 3) call self.sidecar.update_metadata(saved_path,
new_meta), and 4) record the old_meta as an undoable operation via the app's
undo/backup mechanism (e.g., self.undo_manager.record_metadata_change or the
same backup routine used for image data) so operations like crop, auto_levels,
and auto_white_balance can fully revert metadata; apply the same change at the
other same-pattern sites (the blocks used by crop, auto_levels,
auto_white_balance).

Comment thread faststack/app.py
Comment on lines +2055 to +2056
# Success reported but result shape unexpected
log.warning("Save finished with unexpected result shape: %r", result)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Clear the stuck “Saving...” status on malformed success results.

This branch only logs, so the UI can remain on the no-timeout "Saving..." message forever when a save reports success with an unexpected payload.

Proposed fix
         else:
             # Success reported but result shape unexpected
             log.warning("Save finished with unexpected result shape: %r", result)
+            self.update_status_message(
+                "Save finished, but the result could not be processed.",
+                timeout=5000,
+            )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@faststack/app.py` around lines 2055 - 2056, The code currently only logs
unexpected save payloads at the log.warning("Save finished with unexpected
result shape: %r", result) branch, which can leave the UI stuck on the
"Saving..." indicator; update that branch to not only log but also invoke the
same completion/cleanup path used for normal successes (e.g., call the success
handler or emit the save-complete/notify-save-done routine that clears the UI
state and resets any in-progress flags), ensuring the client is notified that
the save finished even when the payload shape is malformed.

Comment on lines +51 to +57
function onIsCroppingChanged() {
if (uiState && uiState.isCropping) {
loupeView.freezeCropImageSource()
} else {
loupeView.releaseCropImageSource()
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Always unwind drag state when crop mode exits.

This handler releases the frozen source, but it does not clear isCropDragging or the zoom/pan locks. If uiState.isCropping flips to false from any path other than the local Escape flow, onReleased will skip endCropInteraction() and the view can stay permanently locked.

💡 Proposed fix
         function onIsCroppingChanged() {
             if (uiState && uiState.isCropping) {
                 loupeView.freezeCropImageSource()
             } else {
+                if (mainMouseArea && mainMouseArea.isCropDragging) {
+                    mainMouseArea.endCropInteraction()
+                }
                 loupeView.releaseCropImageSource()
             }
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function onIsCroppingChanged() {
if (uiState && uiState.isCropping) {
loupeView.freezeCropImageSource()
} else {
loupeView.releaseCropImageSource()
}
}
function onIsCroppingChanged() {
if (uiState && uiState.isCropping) {
loupeView.freezeCropImageSource()
} else {
if (mainMouseArea && mainMouseArea.isCropDragging) {
mainMouseArea.endCropInteraction()
}
loupeView.releaseCropImageSource()
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@faststack/qml/Components.qml` around lines 51 - 57, The onIsCroppingChanged
handler currently only calls loupeView.freezeCropImageSource() /
releaseCropImageSource() and misses unwinding the crop drag state and locks when
uiState.isCropping becomes false; update onIsCroppingChanged (the function that
reacts to uiState.isCropping) so that when uiState.isCropping flips to false it
also ensures any ongoing crop drag is terminated by calling the same cleanup
used in the Escape/local flow (e.g., invoke endCropInteraction() or equivalent),
set uiState.isCropDragging = false, and clear any zoom/pan locks so onReleased
doesn’t skip cleanup and the view is fully unlocked.

Comment on lines 60 to 75
Keys.onEscapePressed: (event) => {
if (uiState && uiState.isCropping) {
if (mainMouseArea.isRotating) {
// Revert rotation
mainMouseArea.cropRotation = mainMouseArea.cropStartRotation
if (controller) controller.set_straighten_angle(mainMouseArea.cropRotation, -1)


mainMouseArea.endCropInteraction()
mainMouseArea.isRotating = false
mainMouseArea.cropDragMode = "none"
mainMouseArea.isCropDragging = false
event.accepted = true
} else if (controller) {
mainMouseArea.endCropInteraction()
controller.cancel_crop_mode()
mainMouseArea.cropRotation = 0 // Reset local rotation
event.accepted = true
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Cancel queued rotation updates before handling Escape.

rotationThrottleTimer may still be armed from the last drag sample. If Escape is pressed before it fires, the callback can re-send the old pendingRotation after the revert/cancel path runs.

💡 Proposed fix
     Keys.onEscapePressed: (event) => {
         if (uiState && uiState.isCropping) {
+            rotationThrottleTimer.stop()
             if (mainMouseArea.isRotating) {
                 // Revert rotation
                 mainMouseArea.cropRotation = mainMouseArea.cropStartRotation
                 if (controller) controller.set_straighten_angle(mainMouseArea.cropRotation, -1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Keys.onEscapePressed: (event) => {
if (uiState && uiState.isCropping) {
if (mainMouseArea.isRotating) {
// Revert rotation
mainMouseArea.cropRotation = mainMouseArea.cropStartRotation
if (controller) controller.set_straighten_angle(mainMouseArea.cropRotation, -1)
mainMouseArea.endCropInteraction()
mainMouseArea.isRotating = false
mainMouseArea.cropDragMode = "none"
mainMouseArea.isCropDragging = false
event.accepted = true
} else if (controller) {
mainMouseArea.endCropInteraction()
controller.cancel_crop_mode()
mainMouseArea.cropRotation = 0 // Reset local rotation
event.accepted = true
}
Keys.onEscapePressed: (event) => {
if (uiState && uiState.isCropping) {
rotationThrottleTimer.stop()
if (mainMouseArea.isRotating) {
// Revert rotation
mainMouseArea.cropRotation = mainMouseArea.cropStartRotation
if (controller) controller.set_straighten_angle(mainMouseArea.cropRotation, -1)
mainMouseArea.endCropInteraction()
mainMouseArea.isRotating = false
event.accepted = true
} else if (controller) {
mainMouseArea.endCropInteraction()
controller.cancel_crop_mode()
mainMouseArea.cropRotation = 0 // Reset local rotation
event.accepted = true
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@faststack/qml/Components.qml` around lines 60 - 75, The escape handler can
let a previously-armed rotationThrottleTimer fire and reapply pendingRotation
after you revert/cancel; update Keys.onEscapePressed to cancel any queued
rotation work by stopping rotationThrottleTimer and clearing the pendingRotation
value (or resetting it to a neutral value) before calling
mainMouseArea.endCropInteraction()/controller.cancel_crop_mode() and resetting
cropRotation; reference rotationThrottleTimer, pendingRotation, mainMouseArea,
and the Keys.onEscapePressed block so the timer is stopped and pendingRotation
cleared in both the rotate-revert and cancel branches.

Comment on lines +658 to +664
function beginNewCrop(mouseX, mouseY, mx, my) {
cropDragMode = "new"
cropStartX = mouseX
cropStartY = mouseY
setCropBoxStart(mx, my, mx, my)
uiState.currentCropBox = [Math.round(mx), Math.round(my), Math.round(mx), Math.round(my)]
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Clamp the initial crop box to image bounds.

beginNewCrop() stores raw normalized coordinates even when the press starts outside the image. A click-release in the viewport margin can leave uiState.currentCropBox with values below 0 or above 1000.

💡 Proposed fix
         function beginNewCrop(mouseX, mouseY, mx, my) {
             cropDragMode = "new"
             cropStartX = mouseX
             cropStartY = mouseY
+            mx = Math.max(0, Math.min(1000, mx))
+            my = Math.max(0, Math.min(1000, my))
             setCropBoxStart(mx, my, mx, my)
             uiState.currentCropBox = [Math.round(mx), Math.round(my), Math.round(mx), Math.round(my)]
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@faststack/qml/Components.qml` around lines 658 - 664, beginNewCrop currently
writes raw normalized coordinates (mx,my) into uiState.currentCropBox and calls
setCropBoxStart even when the pointer is outside the image; clamp mx and my to
the image bounds before using them so values stay within [0,1000] (or your
normalized range) — e.g. compute clampedMx = Math.max(0, Math.min(1000, mx)) and
clampedMy = Math.max(0, Math.min(1000, my)), pass those to setCropBoxStart and
store Math.round(clampedMx), Math.round(clampedMy) in uiState.currentCropBox,
while still setting cropStartX/cropStartY from the original mouseX/mouseY.

@AlanRockefeller AlanRockefeller merged commit 40fcf73 into main Apr 12, 2026
3 checks passed
This was referenced Apr 12, 2026
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.

1 participant