Fix: cannot add point label after selecting a keypoint - #234
Merged
Conversation
Add a dedicated helper to update `layer.current_properties` for the next keypoint while preserving the current selection via `block_update_properties()`. This fixes selected points being unintentionally edited when changing current label/id defaults, and consolidates duplicated setter logic for `current_keypoint`, `current_label`, and `current_id`.
Extend keypoints store tests to cover selection-safety when changing `current_keypoint` and `current_id`. The new cases assert that switching keypoints does not relabel selected points, does not mutate point data/properties when selecting an existing keypoint, and does not affect non-active layers.
Refactors keypoint default updates to capture the requested keypoint before mutating layer properties, then compares it against the actual layer state and emits a warning when they diverge. Also snapshots the current keypoint and annotated set before append logic, so annotation decisions and appended properties use a consistent keypoint view.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes keypoint switching while points are selected and stabilizes annotation properties during point addition.
Changes:
- Updates current properties without relabeling selected points.
- Snapshots the requested keypoint during annotation.
- Adds regression tests for selection and layer isolation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/napari_deeplabcut/core/keypoints.py |
Revises keypoint property updates and add behavior. |
src/napari_deeplabcut/_tests/core/test_keypoints.py |
Adds keypoint-switching regression tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
2 tasks
Add two core keypoint store tests for sequential labeling behavior. One verifies adding keypoints out of header order preserves the explicitly selected label/id for each added point. The other verifies that when a non-first keypoint is manually selected, add() uses that pair for insertion and then advances to the next keypoint in sequence.
Make `KeypointStore.add()` advance from the keypoint requested at the start of the call, even if layer property events mutate `current_keypoint` during the operation. This also fixes QUICK mode updates to index from the captured requested keypoint instead of the potentially changed current one. Added `_next_keypoint_after()` to centralize safe next-keypoint lookup (with a warning for out-of-sequence keypoints) and added a regression test covering the event-callback race case.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/napari_deeplabcut/core/keypoints.py:330
prev_keypoint()still callsself._keypoints.index(self.current_keypoint)without handlingValueError. Sincenext_keypoint()now explicitly handles the case wherecurrent_keypointis outside the configured sequence,prev_keypoint()can still crash in the same scenario (e.g., if events or malformedcurrent_propertiesproduce a keypoint not present inself._keypoints). Consider mirroring the defensive behavior here as well.
def prev_keypoint(self, *args):
ind = self._keypoints.index(self.current_keypoint) - 1
if ind >= 0:
self.current_keypoint = self._keypoints[ind]
C-Achard
marked this pull request as ready for review
August 10, 2026 14:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes keypoint switching and out-of-order annotation when Napari events occur during an add.
Closes #233
Fix
block_update_properties()so selected points are not relabeled and remain selected(bodypart, individual)pair once at the start ofadd(), such that duplicate detection, property assignment, and QUICK-mode lookup use a consistent keypointWhy
Previously,
add()readcurrent_keypointmultiple times. Updating layer data could trigger events that changed the current properties mid-operation, causing the new point to receive an incorrect pair or leaving the store in an inconsistent sequence state.Tests
Regression tests added:
(bodypart, individual)pair does not relabel or deselect an existing point