From e70baa79070d065f16feea1e5672c5012a17dc11 Mon Sep 17 00:00:00 2001 From: Oakchris1955 <80592203+Oakchris1955@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:43:35 +0300 Subject: [PATCH 1/5] Prevent highlighting on error console --- src/textual/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textual/app.py b/src/textual/app.py index 970dea764b..53d420517f 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -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.""" From 8471e5d965309bd9082d04a032c24a0edcf8c499 Mon Sep 17 00:00:00 2001 From: Oakchris1955 <80592203+Oakchris1955@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:49:06 +0300 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 931d541c0c..3832f8a7cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Changed + +- When displaying a message using `App.exit()`, the console no longer highlights things such as numbers. + ## [0.58.0] - 2024-04-25 ### Fixed From 20c1776baf913674d70a382418383e810431d347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A2muran=20=C4=B0mran?= <73625486+kamurani@users.noreply.github.com> Date: Thu, 2 May 2024 02:22:09 +1000 Subject: [PATCH 3/5] fix typo (#4468) --- docs/widgets/text_area.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/widgets/text_area.md b/docs/widgets/text_area.md index 9e24442d30..5747d394ec 100644 --- a/docs/widgets/text_area.md +++ b/docs/widgets/text_area.md @@ -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 From bf3dceed33639d9d57220f7005a073b4e1d84ead Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 2 May 2024 09:50:27 +0100 Subject: [PATCH 4/5] just docs --- src/textual/css/scalar.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/textual/css/scalar.py b/src/textual/css/scalar.py index 0ef332c571..849f566732 100644 --- a/src/textual/css/scalar.py +++ b/src/textual/css/scalar.py @@ -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 From 5d974391edacf71adb450a96756634ccee2559da Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Thu, 2 May 2024 16:24:52 +0100 Subject: [PATCH 5/5] fix(list view): fix bugs with initial index (#4452) * fix(list view): fix bugs with initial index * update changelog --- CHANGELOG.md | 5 +++ src/textual/widgets/_list_view.py | 5 ++- tests/listview/test_listview_initial_index.py | 42 +++++++++++++++++++ tests/listview/test_listview_navigation.py | 1 - 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tests/listview/test_listview_initial_index.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 229e995f4f..88847d849e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed + +- Fixed `ListView` bugs with the initial index https://github.com/Textualize/textual/pull/4452 ## Unreleased diff --git a/src/textual/widgets/_list_view.py b/src/textual/widgets/_list_view.py index bc51a9ead7..77cfc75bc9 100644 --- a/src/textual/widgets/_list_view.py +++ b/src/textual/widgets/_list_view.py @@ -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: diff --git a/tests/listview/test_listview_initial_index.py b/tests/listview/test_listview_initial_index.py new file mode 100644 index 0000000000..515de4f044 --- /dev/null +++ b/tests/listview/test_listview_initial_index.py @@ -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 diff --git a/tests/listview/test_listview_navigation.py b/tests/listview/test_listview_navigation.py index 4a93bb2695..680b8ced68 100644 --- a/tests/listview/test_listview_navigation.py +++ b/tests/listview/test_listview_navigation.py @@ -35,7 +35,6 @@ async def test_keyboard_navigation_with_disabled_items() -> None: await pilot.press("up") assert app.highlighted == [ - None, "1", "4", "5",