Skip to content

Commit 8029231

Browse files
authored
Merge pull request #5558 from Textualize/smooth-scroll-detect
Smooth scrolling detection
2 parents 369feef + adf1b7d commit 8029231

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- Fixed height of auto container which contains auto height children https://github.com/Textualize/textual/pull/5552
1414
- Fixed `Content.from_markup` not stripping control codes https://github.com/Textualize/textual/pull/5557
1515
- Fixed `delta_x` and `delta_y` in mouse events when smooth scrolling is enabled https://github.com/Textualize/textual/pull/5556
16+
- Fixed detection of smooth scrolling https://github.com/Textualize/textual/pull/5558
1617

1718
### Added
1819

1920
- Added `pointer_x`, `pointer_y`, `pointer_screen_x`, and `pointer_screen_y` attributes to mouse events https://github.com/Textualize/textual/pull/5556
2021

22+
### Changed
23+
24+
- Animating the scrollbar while dragging is disabled if smooth scrolling is available https://github.com/Textualize/textual/pull/5558
25+
- Renamed `TerminalSupportsInBandWindowResize` to `InBandWindowResize` https://github.com/Textualize/textual/pull/5558
26+
2127
## [2.0.4] - 2025-02-17
2228

2329
### Fixed

src/textual/_xterm_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,10 @@ def send_escape() -> None:
298298
and not IS_ITERM
299299
):
300300
# TODO: iTerm is buggy in one or more of the protocols required here
301-
in_band_event = messages.TerminalSupportInBandWindowResize.from_setting_parameter(
302-
setting_parameter
301+
in_band_event = (
302+
messages.InBandWindowResize.from_setting_parameter(
303+
setting_parameter
304+
)
303305
)
304306
on_token(in_band_event)
305307
break

src/textual/app.py

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

798-
self.supports_smooth_scrolling: bool = True
798+
self.supports_smooth_scrolling: bool = False
799799
"""Does the terminal support smooth scrolling?"""
800800

801801
if self.ENABLE_COMMAND_PALETTE:
@@ -4647,14 +4647,10 @@ def _on_delivery_failed(self, event: events.DeliveryComplete) -> None:
46474647
"Failed to save screenshot", title="Screenshot", severity="error"
46484648
)
46494649

4650-
@on(messages.TerminalSupportInBandWindowResize)
4651-
def _on_terminal_supports_in_band_window_resize(
4652-
self, message: messages.TerminalSupportInBandWindowResize
4653-
) -> None:
4654-
"""There isn't much we can do with this information currently, so
4655-
we will just log it.
4656-
"""
4657-
self.supports_smooth_scrolling = True
4650+
@on(messages.InBandWindowResize)
4651+
def _on_in_band_window_resize(self, message: messages.InBandWindowResize) -> None:
4652+
"""In band window resize enables smooth scrolling."""
4653+
self.supports_smooth_scrolling = message.enabled
46584654
self.log.debug(message)
46594655

46604656
def _on_idle(self) -> None:

src/textual/drivers/linux_driver.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from textual.drivers._writer_thread import WriterThread
2222
from textual.geometry import Size
2323
from textual.message import Message
24-
from textual.messages import TerminalSupportInBandWindowResize
24+
from textual.messages import InBandWindowResize
2525

2626
if TYPE_CHECKING:
2727
from textual.app import App
@@ -453,7 +453,7 @@ def process_selector_events(
453453

454454
def process_message(self, message: Message) -> None:
455455
# intercept in-band window resize
456-
if isinstance(message, TerminalSupportInBandWindowResize):
456+
if isinstance(message, InBandWindowResize):
457457
if message.supported:
458458
self._in_band_window_resize = True
459459
if message.enabled:
@@ -462,9 +462,7 @@ def process_message(self, message: Message) -> None:
462462
else:
463463
# Supported, but not enabled
464464
self._enable_in_band_window_resize()
465-
super().process_message(
466-
TerminalSupportInBandWindowResize(True, True)
467-
)
465+
super().process_message(InBandWindowResize(True, True))
468466
self._enable_mouse_pixels()
469467
return
470468

src/textual/messages.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class TerminalSupportsSynchronizedOutput(Message):
100100

101101

102102
@rich.repr.auto
103-
class TerminalSupportInBandWindowResize(Message):
103+
class InBandWindowResize(Message):
104104
"""Reports if the in-band window resize protocol is supported.
105105
106106
https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83"""
@@ -121,18 +121,16 @@ def __rich_repr__(self) -> rich.repr.Result:
121121
yield "enabled", self.enabled
122122

123123
@classmethod
124-
def from_setting_parameter(
125-
cls, setting_parameter: int
126-
) -> TerminalSupportInBandWindowResize:
124+
def from_setting_parameter(cls, setting_parameter: int) -> InBandWindowResize:
127125
"""Construct the message from the setting parameter.
128126
129127
Args:
130128
setting_parameter: Setting parameter from stdin.
131129
132130
Returns:
133-
New TerminalSupportInBandWindowResize instance.
131+
New InBandWindowResize instance.
134132
"""
135133

136134
supported = setting_parameter not in (0, 4)
137135
enabled = setting_parameter in (1, 3)
138-
return TerminalSupportInBandWindowResize(supported, enabled)
136+
return InBandWindowResize(supported, enabled)

src/textual/scrollbar.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ async def _on_mouse_move(self, event: events.MouseMove) -> None:
379379
(event._screen_x - self.grabbed.x)
380380
* (virtual_size / self.window_size)
381381
)
382-
self.post_message(ScrollTo(x=x, y=y))
382+
self.post_message(
383+
ScrollTo(x=x, y=y, animate=not self.app.supports_smooth_scrolling)
384+
)
383385
event.stop()
384386

385387
async def _on_click(self, event: events.Click) -> None:

0 commit comments

Comments
 (0)