From 8689e24a1eae6ec3a0024dfbc7127de52305eea6 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 27 May 2022 11:19:02 +0100 Subject: [PATCH 1/3] Refresh scrollbars on style changes. Instantiate text input visible range to (0,0) by default. Remove debug code. --- sandbox/file_search.scss | 4 ++-- src/textual/css/stylesheet.py | 21 ++++++++++++--------- src/textual/dom.py | 1 + src/textual/widgets/text_input.py | 15 +-------------- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/sandbox/file_search.scss b/sandbox/file_search.scss index 5163bd5b16..29e1049070 100644 --- a/sandbox/file_search.scss +++ b/sandbox/file_search.scss @@ -5,8 +5,8 @@ Screen { #file_table_wrapper { dock: bottom; - height: auto; - overflow: auto auto; + height: 20; + overflow: auto scroll; scrollbar-color: $accent-darken-1; } diff --git a/src/textual/css/stylesheet.py b/src/textual/css/stylesheet.py index cd4d86db83..6d2ee5a89b 100644 --- a/src/textual/css/stylesheet.py +++ b/src/textual/css/stylesheet.py @@ -15,6 +15,7 @@ from rich.syntax import Syntax from rich.text import Text +from textual.widget import Widget from .errors import StylesheetError from .match import _check_selectors from .model import RuleSet @@ -304,6 +305,8 @@ def apply(self, node: DOMNode, animate: bool = False) -> None: }, ) self.replace_rules(node, node_rules, animate=animate) + if isinstance(node, Widget): + node._refresh_scrollbars() @classmethod def replace_rules( @@ -383,15 +386,15 @@ def update(self, root: DOMNode, animate: bool = False) -> None: from rich.traceback import install install(show_locals=True) - - class Widget(DOMNode): - pass - - class View(DOMNode): - pass - - class App(DOMNode): - pass + # + # class Widget(DOMNode): + # pass + # + # class View(DOMNode): + # pass + # + # class App(DOMNode): + # pass app = App() main_view = View(id="main") diff --git a/src/textual/dom.py b/src/textual/dom.py index 700534398b..3abfbc682f 100644 --- a/src/textual/dom.py +++ b/src/textual/dom.py @@ -343,6 +343,7 @@ def get_pseudo_classes(self) -> Iterable[str]: return () def reset_styles(self) -> None: + """Reset styles back to their initial state""" from .widget import Widget for node in self.walk_children(): diff --git a/src/textual/widgets/text_input.py b/src/textual/widgets/text_input.py index bb719bbc21..175af301b6 100644 --- a/src/textual/widgets/text_input.py +++ b/src/textual/widgets/text_input.py @@ -1,6 +1,5 @@ from __future__ import annotations -import time from typing import Callable from rich.cells import cell_len @@ -135,7 +134,7 @@ def __init__( super().__init__(name=name, id=id, classes=classes) self.placeholder = placeholder self._editor = TextEditorBackend(initial, 0) - self.visible_range: tuple[int, int] | None = None + self.visible_range: tuple[int, int] = (0, 0) self.autocompleter = autocompleter self._suggestion_suffix = "" @@ -282,18 +281,6 @@ def on_key(self, event: events.Key) -> None: if visible_content_to_cursor_cell_len + key_cell_len >= available_width: self.visible_range = start + key_cell_len, end + key_cell_len self._update_suggestion(event) - elif ( - key == "ctrl+x" - ): # TODO: This allows us to query and print the text input state - self.log(start=start) - self.log(end=end) - self.log(visible_content=visible_content) - self.log(visible_content_cell_len=visible_content_cell_len) - self.log( - visible_content_to_cursor_cell_len=visible_content_to_cursor_cell_len - ) - self.log(available_width=available_width) - self.log(cursor_index=self._editor.cursor_index) elif key == "enter" and self._editor.content: self.post_message_no_wait(TextInput.Submitted(self, self._editor.content)) elif key == "right": From 71af2ae0a09ea96ce5699a91d2a65d880b88a9d2 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 27 May 2022 11:24:54 +0100 Subject: [PATCH 2/3] Revert file search sandbox example --- sandbox/file_search.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sandbox/file_search.scss b/sandbox/file_search.scss index 29e1049070..5163bd5b16 100644 --- a/sandbox/file_search.scss +++ b/sandbox/file_search.scss @@ -5,8 +5,8 @@ Screen { #file_table_wrapper { dock: bottom; - height: 20; - overflow: auto scroll; + height: auto; + overflow: auto auto; scrollbar-color: $accent-darken-1; } From 79bc21f2de4b3eba477a1872e7e912245e7d33f2 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Fri, 27 May 2022 11:31:39 +0100 Subject: [PATCH 3/3] Revert stylesheet __main__ block --- src/textual/css/stylesheet.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/textual/css/stylesheet.py b/src/textual/css/stylesheet.py index 6d2ee5a89b..84bab60a47 100644 --- a/src/textual/css/stylesheet.py +++ b/src/textual/css/stylesheet.py @@ -386,15 +386,15 @@ def update(self, root: DOMNode, animate: bool = False) -> None: from rich.traceback import install install(show_locals=True) - # - # class Widget(DOMNode): - # pass - # - # class View(DOMNode): - # pass - # - # class App(DOMNode): - # pass + + class Widget(DOMNode): + pass + + class View(DOMNode): + pass + + class App(DOMNode): + pass app = App() main_view = View(id="main")