Skip to content

Commit 9179c74

Browse files
committed
expose smooth scrolling
1 parent 2b41ff1 commit 9179c74

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/textual/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ def __init__(
795795
self._clipboard: str = ""
796796
"""Contents of local clipboard."""
797797

798+
self.supports_smooth_scrolling: bool = True
799+
"""Does the terminal support smooth scrolling?"""
800+
798801
if self.ENABLE_COMMAND_PALETTE:
799802
for _key, binding in self._bindings:
800803
if binding.action in {"command_palette", "app.command_palette"}:
@@ -4632,6 +4635,7 @@ def _on_terminal_supports_in_band_window_resize(
46324635
"""There isn't much we can do with this information currently, so
46334636
we will just log it.
46344637
"""
4638+
self.supports_smooth_scrolling = True
46354639
self.log.debug(message)
46364640

46374641
def _on_idle(self) -> None:

src/textual/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,5 @@ def _get_textual_animations() -> AnimationLevel:
159159
"""
160160

161161
SMOOTH_SCROLL: Final[bool] = _get_environ_int("TEXTUAL_SMOOTH_SCROLL", 1) == 1
162-
"""Should smooth scrolling be enabled? set `TEXTUAL_SMOOTH_SCROLL=0` to disable smooth scrolling.
162+
"""Should smooth scrolling be enabled? set `TEXTUAL_SMOOTH_SCROLL=0` to disable smooth
163163
"""

src/textual/widget.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,26 +1693,26 @@ def watch_hover_style(
16931693
self.highlight_link_id = hover_style.link_id
16941694

16951695
def watch_scroll_x(self, old_value: float, new_value: float) -> None:
1696-
self.horizontal_scrollbar.position = round(new_value)
1697-
if (old_value) != (new_value):
1696+
self.horizontal_scrollbar.position = new_value
1697+
if round(old_value) != round(new_value):
16981698
self._refresh_scroll()
16991699

17001700
def watch_scroll_y(self, old_value: float, new_value: float) -> None:
1701-
self.vertical_scrollbar.position = round(new_value)
1702-
if (old_value) != (new_value):
1701+
self.vertical_scrollbar.position = new_value
1702+
if round(old_value) != round(new_value):
17031703
self._refresh_scroll()
17041704

17051705
def validate_scroll_x(self, value: float) -> float:
17061706
return clamp(value, 0, self.max_scroll_x)
17071707

17081708
def validate_scroll_target_x(self, value: float) -> float:
1709-
return clamp(value, 0, self.max_scroll_x)
1709+
return round(clamp(value, 0, self.max_scroll_x))
17101710

17111711
def validate_scroll_y(self, value: float) -> float:
17121712
return clamp(value, 0, self.max_scroll_y)
17131713

17141714
def validate_scroll_target_y(self, value: float) -> float:
1715-
return clamp(value, 0, self.max_scroll_y)
1715+
return round(clamp(value, 0, self.max_scroll_y))
17161716

17171717
@property
17181718
def max_scroll_x(self) -> int:

0 commit comments

Comments
 (0)