Skip to content

fix(tools): support contour segmentation undo and redo#2817

Merged
sedghi merged 1 commit into
mainfrom
codex/fix-contour-segmentation-undo-redo
Jul 19, 2026
Merged

fix(tools): support contour segmentation undo and redo#2817
sedghi merged 1 commit into
mainfrom
codex/fix-contour-segmentation-undo-redo

Conversation

@sedghi

@sedghi sedghi commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

  • preserve contour-segmentation state across undo/redo after boolean stroke processing replaces the source annotation
  • add Undo/Redo controls and standard keyboard shortcuts to the planar freehand contour segmentation example
  • add HistoryMemo unit coverage and a browser-state regression for contour merge → undo → redo
  • update the GenericViewport test harness to use the current RenderBackends enum name

Root cause

The planar freehand tool initially records an annotation-creation memo for the source stroke. Contour boolean processing then removes that source annotation and rebuilds the resulting contour annotations, leaving the memo pointed at an annotation that no longer exists. Undo therefore could not remove the committed contour, and redo could restore the obsolete source stroke.

This change replaces that provisional memo in-place with a memo that swaps the complete pre-stroke and post-stroke annotation sets, preserving a single undo step for creation, merges, and holes.

Validation

  • corepack pnpm run test:vitest:browser tests/vitest-browser/undoRedoHistory.browser.test.ts — 9 passed, 1 expected failure
  • corepack pnpm exec jest packages/core/test/utilities/historyMemo.jest.js --runInBand — 5 passed
  • corepack pnpm exec tsc --project packages/core/tsconfig.json
  • corepack pnpm exec tsc --project packages/tools/tsconfig.json
  • Prettier, oxlint, and git diff --check

Summary by CodeRabbit

  • New Features

    • Added support for replacing the current history entry while preserving undo/redo position.
    • Added undo and redo controls to the planar freehand contour segmentation example.
    • Added keyboard shortcuts: Ctrl/Cmd+Z for undo and Ctrl/Cmd+Y or Ctrl/Cmd+Shift+Z for redo.
    • Contour merge and editing actions now support reliable undo and redo restoration.
  • Bug Fixes

    • Improved history handling for grouped contour edits and restored annotations.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4a339f37-1e6d-47ec-b027-9f7dca548551

📥 Commits

Reviewing files that changed from the base of the PR and between a0bb6c5 and a1866db.

📒 Files selected for processing (7)
  • packages/core/src/utilities/historyMemo/index.ts
  • packages/core/test/utilities/historyMemo.jest.js
  • packages/tools/examples/planarFreehandContourSegmentationTool/index.ts
  • packages/tools/src/utilities/contourSegmentation/applyContourStroke.ts
  • tests/vitest-browser/harness/createPlanarViewport.ts
  • tests/vitest-browser/harness/tools.ts
  • tests/vitest-browser/undoRedoHistory.browser.test.ts

📝 Walkthrough

Walkthrough

Adds HistoryMemo.replaceCurrentMemo, integrates contour stroke merging with undo/redo annotation restoration, updates the planar contour example with controls and shortcuts, and adds browser test coverage and gesture support.

Changes

Contour history

Layer / File(s) Summary
Current memo replacement
packages/core/src/utilities/historyMemo/index.ts, packages/core/test/utilities/historyMemo.jest.js
Adds replacement of matching current history entries for both grouped and non-grouped memos, with guard handling and tests.
Contour stroke history integration
packages/tools/src/utilities/contourSegmentation/applyContourStroke.ts
Tracks previous and resulting annotations and registers undo/redo callbacks that swap stored annotations through DefaultHistoryMemo.
Example undo and redo controls
packages/tools/examples/planarFreehandContourSegmentationTool/index.ts
Adds toolbar buttons, keyboard shortcuts, and instructions for contour undo and redo.
Browser history validation and gesture support
tests/vitest-browser/harness/tools.ts, tests/vitest-browser/undoRedoHistory.browser.test.ts, tests/vitest-browser/harness/createPlanarViewport.ts
Adds a drag-path helper, validates contour merge undo/redo behavior, and updates planar render backend enum usage.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant applyStroke
  participant DefaultHistoryMemo
  participant AnnotationState
  User->>applyStroke: draw contour stroke
  applyStroke->>AnnotationState: create merged annotations
  applyStroke->>DefaultHistoryMemo: replace current memo
  User->>DefaultHistoryMemo: undo or redo
  DefaultHistoryMemo->>AnnotationState: restore previous or resulting annotations
Loading

Possibly related PRs

Suggested reviewers: wayfarer3130

✨ 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 codex/fix-contour-segmentation-undo-redo

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.

@sedghi
sedghi marked this pull request as ready for review July 19, 2026 20:44

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.

Tip: disable this comment in your organization's Code Review settings.

@sedghi
sedghi merged commit 5cfd10a into main Jul 19, 2026
17 checks passed
sedghi added a commit to OHIF/Viewers that referenced this pull request Jul 19, 2026
* fix(cornerstone): bump cornerstone3D to 5.6.8

Bumps all @cornerstonejs/* packages 5.6.7 -> 5.6.8: contour segmentation undo/redo fix (cornerstonejs/cornerstone3D#2817)

* fix(deps): pin adm-zip to 0.6.0

dcmjs pins adm-zip 0.5.17 but does not import it in runtime code; 0.6.0
patches GHSA-xcpc-8h2w-3j85, which trips the lockfile audit gate on any
lockfile-touching PR.
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