diff --git a/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py b/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py index 388d80c5e1b..ade9643d6ba 100644 --- a/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py +++ b/napari/layers/shapes/_tests/test_shapes_mouse_bindings.py @@ -104,6 +104,10 @@ def test_add_simple_shape(shape_type, create_known_shapes_layer): np.testing.assert_allclose(new_shape_max, known_non_shape_end) assert layer.shape_type[-1] == shape_type + # Ensure it's selected, accounting for zero-indexing + assert len(layer.selected_data) == 1 + assert layer.selected_data == {n_shapes} + def test_polygon_lasso_tablet(create_known_shapes_layer): """Draw polygon with tablet simulated by mouse drag event.""" @@ -145,6 +149,10 @@ def test_polygon_lasso_tablet(create_known_shapes_layer): assert layer.shape_type[-1] == 'polygon' assert not layer._is_creating + # Ensure it's selected, accounting for zero-indexing + assert len(layer.selected_data) == 1 + assert layer.selected_data == {n_shapes} + def test_polygon_lasso_mouse(create_known_shapes_layer): """Draw polygon with mouse. Events in sequence are mouse press, release, move, press, release""" @@ -182,6 +190,10 @@ def test_polygon_lasso_mouse(create_known_shapes_layer): assert layer.shape_type[-1] == 'polygon' assert not layer._is_creating + # Ensure it's selected, accounting for zero-indexing + assert len(layer.selected_data) == 1 + assert layer.selected_data == {n_shapes} + def test_distance_polygon_creating(create_known_shapes_layer): """Test that distance threshold in polygon creating works as intended""" @@ -249,6 +261,10 @@ def test_add_complex_shape(shape_type, create_known_shapes_layer): np.testing.assert_allclose(layer.data[-1], desired_shape) assert layer.shape_type[-1] == shape_type + # Ensure it's selected, accounting for zero-indexing + assert len(layer.selected_data) == 1 + assert layer.selected_data == {n_shapes} + def test_vertex_insert(create_known_shapes_layer): """Add vertex to shape.""" diff --git a/napari/layers/shapes/shapes.py b/napari/layers/shapes/shapes.py index cf18ad5b219..a9f3aa25eff 100644 --- a/napari/layers/shapes/shapes.py +++ b/napari/layers/shapes/shapes.py @@ -2570,7 +2570,6 @@ def _finish_drawing(self, event=None): """Reset properties used in shape drawing.""" index = copy(self._moving_value[0]) self._is_moving = False - self.selected_data = set() self._drag_start = None self._drag_box = None self._is_selecting = False