diff --git a/src/pick/__init__.py b/src/pick/__init__.py index d9535a8..6858644 100644 --- a/src/pick/__init__.py +++ b/src/pick/__init__.py @@ -104,6 +104,9 @@ def move_down(self) -> None: def mark_index(self) -> None: if self.multiselect: + option = self.options[self.index] + if isinstance(option, Option) and not option.enabled: + return if self.index in self.selected_indexes: self.selected_indexes.remove(self.index) else: diff --git a/tests/test_pick.py b/tests/test_pick.py index acec4c3..759d086 100644 --- a/tests/test_pick.py +++ b/tests/test_pick.py @@ -77,3 +77,11 @@ def test_disabled_option(): assert picker.get_selected() == (Option("option1"), 0) picker.move_down() assert picker.get_selected() == (Option("option3"), 2) + + +def test_mark_index_disabled_option(): + options = [Option("option1"), Option("option2", enabled=False), Option("option3")] + picker = Picker(options, multiselect=True) + picker.index = 1 # Point directly to disabled option2 + picker.mark_index() + assert picker.get_selected() == [] # Disabled option should NOT be marked