Skip to content

Commit

Permalink
Merge branch 'main' into fix-selection-list-update-indexes-after-opti…
Browse files Browse the repository at this point in the history
…on-removed
  • Loading branch information
darrenburns authored May 2, 2024
2 parents 7c4610e + 5d97439 commit edbd272
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fixed `SelectionList` issues after removing an option https://github.com/Textualize/textual/pull/4464
- Fixed `ListView` bugs with the initial index https://github.com/Textualize/textual/pull/4452

### Changed

- When displaying a message using `App.exit()`, the console no longer highlights things such as numbers.

## [0.58.1] - 2024-05-01

Expand All @@ -19,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed intermittent issue with scrolling to focus https://github.com/Textualize/textual/commit/567caf8acb196260adf6a0a6250e3ff5093056d0
- Fixed issue with scrolling to center https://github.com/Textualize/textual/pull/4469


## [0.58.0] - 2024-04-25

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion docs/widgets/text_area.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ We can freely edit the text, and the syntax highlighting will update immediately
Recall that we map names (like `@heading`) from the tree-sitter highlight query to Rich style objects inside the `TextAreaTheme.syntax_styles` dictionary.
If you notice some highlights are missing after registering a language, the issue may be:

1. The current `TextAreaTheme` doesn't contain a mapping for the name in the highlight query. Adding a new to `syntax_styles` should resolve the issue.
1. The current `TextAreaTheme` doesn't contain a mapping for the name in the highlight query. Adding a new key-value pair to `syntax_styles` should resolve the issue.
2. The highlight query doesn't assign a name to the pattern you expect to be highlighted. In this case you'll need to update the highlight query to assign to the name.

!!! tip
Expand Down
2 changes: 1 addition & 1 deletion src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def __init__(
soft_wrap=False,
)
self._workers = WorkerManager(self)
self.error_console = Console(markup=False, stderr=True)
self.error_console = Console(markup=False, highlight=False, stderr=True)
self.driver_class = driver_class or self.get_driver_class()
self._screen_stacks: dict[str, list[Screen[Any]]] = {"_default": []}
"""A stack of screens per mode."""
Expand Down
6 changes: 3 additions & 3 deletions src/textual/css/scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@


class ScalarError(Exception):
pass
"""Base class for exceptions raised by the Scalar class."""


class ScalarResolveError(ScalarError):
pass
"""Raised for errors resolving scalars (unlikely to occur in practice)."""


class ScalarParseError(ScalarError):
pass
"""Raised when a scalar couldn't be parsed from a string."""


@unique
Expand Down
5 changes: 3 additions & 2 deletions src/textual/widgets/_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def __init__(
)
# Set the index to the given initial index, or the first available index after.
self._index = _widget_navigation.find_next_enabled(
self._nodes,
anchor=initial_index - 1 if initial_index is not None else None,
children,
anchor=initial_index if initial_index is not None else None,
direction=1,
with_anchor=True,
)

def _on_mount(self, _: Mount) -> None:
Expand Down
42 changes: 42 additions & 0 deletions tests/listview/test_listview_initial_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest

from textual.app import App, ComposeResult
from textual.widgets import Label, ListItem, ListView


@pytest.mark.parametrize(
"initial_index,expected_index",
[
(0, 1),
(1, 1),
(2, 4),
(3, 4),
(4, 4),
(5, 5),
(6, 7),
(7, 7),
(8, 1),
],
)
async def test_listview_initial_index(initial_index, expected_index) -> None:
"""Regression test for https://github.com/Textualize/textual/issues/4449"""

class ListViewDisabledItemsApp(App[None]):
def compose(self) -> ComposeResult:
yield ListView(
ListItem(Label("0"), disabled=True),
ListItem(Label("1")),
ListItem(Label("2"), disabled=True),
ListItem(Label("3"), disabled=True),
ListItem(Label("4")),
ListItem(Label("5")),
ListItem(Label("6"), disabled=True),
ListItem(Label("7")),
ListItem(Label("8"), disabled=True),
initial_index=initial_index,
)

app = ListViewDisabledItemsApp()
async with app.run_test() as pilot:
list_view = pilot.app.query_one(ListView)
assert list_view._index == expected_index
1 change: 0 additions & 1 deletion tests/listview/test_listview_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ async def test_keyboard_navigation_with_disabled_items() -> None:
await pilot.press("up")

assert app.highlighted == [
None,
"1",
"4",
"5",
Expand Down

0 comments on commit edbd272

Please sign in to comment.