Skip to content

Commit

Permalink
Merge pull request #545 from Textualize/hot-reload-scrollbars
Browse files Browse the repository at this point in the history
Refresh scrollbars on style changes.
  • Loading branch information
willmcgugan authored May 27, 2022
2 parents a65b538 + 79bc21f commit d14a759
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/textual/css/stylesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
15 changes: 1 addition & 14 deletions src/textual/widgets/text_input.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import time
from typing import Callable

from rich.cells import cell_len
Expand Down Expand Up @@ -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 = ""

Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit d14a759

Please sign in to comment.