mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #3274 from davep/fix-optionlist-hover-remove-crash
Fix an OptionList crash when removing an option during mouse hover
This commit is contained in:
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed a crash when removing an option from an `OptionList` while the mouse is hovering over the last option https://github.com/Textualize/textual/issues/3270
|
||||||
|
|
||||||
## [0.36.0] - 2023-09-05
|
## [0.36.0] - 2023-09-05
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -613,6 +613,7 @@ class OptionList(ScrollView, can_focus=True):
|
|||||||
self._refresh_content_tracking(force=True)
|
self._refresh_content_tracking(force=True)
|
||||||
# Force a re-validation of the highlight.
|
# Force a re-validation of the highlight.
|
||||||
self.highlighted = self.highlighted
|
self.highlighted = self.highlighted
|
||||||
|
self._mouse_hovering_over = None
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def remove_option(self, option_id: str) -> Self:
|
def remove_option(self, option_id: str) -> Self:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
|
from textual.geometry import Offset
|
||||||
from textual.widgets import OptionList
|
from textual.widgets import OptionList
|
||||||
from textual.widgets.option_list import Option, OptionDoesNotExist
|
from textual.widgets.option_list import Option, OptionDoesNotExist
|
||||||
|
|
||||||
@@ -99,3 +100,13 @@ async def test_remove_invalid_index() -> None:
|
|||||||
async with OptionListApp().run_test() as pilot:
|
async with OptionListApp().run_test() as pilot:
|
||||||
with pytest.raises(OptionDoesNotExist):
|
with pytest.raises(OptionDoesNotExist):
|
||||||
pilot.app.query_one(OptionList).remove_option_at_index(23)
|
pilot.app.query_one(OptionList).remove_option_at_index(23)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_remove_with_hover_on_last_option():
|
||||||
|
"""https://github.com/Textualize/textual/issues/3270"""
|
||||||
|
async with OptionListApp().run_test() as pilot:
|
||||||
|
await pilot.hover(OptionList, Offset(1, 1) + Offset(2, 1))
|
||||||
|
option_list = pilot.app.query_one(OptionList)
|
||||||
|
assert option_list._mouse_hovering_over == 1
|
||||||
|
option_list.remove_option_at_index(0)
|
||||||
|
assert option_list._mouse_hovering_over == None
|
||||||
|
|||||||
Reference in New Issue
Block a user