Skip to content

Conversation

@prathamesh-patil-5090
Copy link
Contributor

Issue - #9044

I've successfully identified and fixed the bug where slicing doesn't work after deleting a sliced annotation. The issue was caused by improper state synchronization between the UI and the canvas model.

Root Cause

The bug occurred because:

  1. When a slice operation completed successfully, the canvas view dispatched a canvas.sliced event and the UI properly updated its activeControl state to CURSOR
  2. However, the canvas model state still had sliceData.enabled = true
  3. When the user tried to slice again, calling canvasInstance.slice({ enabled: true }) did nothing because the model saw that slicing was already "enabled" and returned early
  4. Pressing ESC worked because it called canvasInstance.cancel() which properly reset the canvas state

Changes Made

I fixed the issue in two files with four changes total:

  1. slice-control.tsx:50-51

    • Added updateActiveControl(ActiveControl.CURSOR) when manually deactivating slice mode
    • This ensures the UI state is properly synced when the user clicks the slice button to turn it off
  2. canvas-wrapper.tsx:881

    • Added canvasInstance.slice({ enabled: false }) in the onCanvasSliceDone handler
    • This ensures the canvas model state is properly reset after a slice operation completes
  3. join-control.tsx:52 (preventive fix)

    • Added updateActiveControl(ActiveControl.CURSOR) when manually deactivating join mode
    • This prevents the same bug from occurring with the join feature
  4. canvas-wrapper.tsx:728 (preventive fix)

    • Added canvasInstance.join({ enabled: false }) in the onCanvasObjectsJoined handler
    • This prevents the same synchronization issue with join operations

Testing

The fix should now allow the following workflow to work correctly:

  1. Draw a polygon or mask
  2. Edit → Slice → Complete the slice
  3. Delete the sliced piece
  4. Edit → Slice again → Should work without needing to press ESC

Proof

Screen.Recording.2025-12-12.015103.mp4

@sonarqubecloud
Copy link

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