Skip to content

Commit 0b2c9db

Browse files
authored
Merge pull request #2140 from blazra/master
Improve `TextEditor` slow scrolling behavior with touchpads
2 parents 358f004 + 7197984 commit 0b2c9db

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8585
- Incorrect unit in `system::Information`. [#2223](https://github.com/iced-rs/iced/pull/2223)
8686
- `size_hint` not being called from `element::Map`. [#2224](https://github.com/iced-rs/iced/pull/2224)
8787
- `size_hint` not being called from `element::Explain`. [#2225](https://github.com/iced-rs/iced/pull/2225)
88+
- Slow touch scrolling for `TextEditor` widget. [#2140](https://github.com/iced-rs/iced/pull/2140)
8889

8990
Many thanks to...
9091

@@ -93,6 +94,7 @@ Many thanks to...
9394
- @arslee07
9495
- @AustinMReppert
9596
- @avsaase
97+
- @blazra
9698
- @brianch
9799
- @bungoboingo
98100
- @Calastrophe

widget/src/text_editor.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ struct State<Highlighter: text::Highlighter> {
289289
is_focused: bool,
290290
last_click: Option<mouse::Click>,
291291
drag_click: Option<mouse::click::Kind>,
292+
partial_scroll: f32,
292293
highlighter: RefCell<Highlighter>,
293294
highlighter_settings: Highlighter::Settings,
294295
highlighter_format_address: usize,
@@ -310,6 +311,7 @@ where
310311
is_focused: false,
311312
last_click: None,
312313
drag_click: None,
314+
partial_scroll: 0.0,
313315
highlighter: RefCell::new(Highlighter::new(
314316
&self.highlighter_settings,
315317
)),
@@ -404,6 +406,14 @@ where
404406

405407
shell.publish(on_edit(action));
406408
}
409+
Update::Scroll(lines) => {
410+
let lines = lines + state.partial_scroll;
411+
state.partial_scroll = lines.fract();
412+
413+
shell.publish(on_edit(Action::Scroll {
414+
lines: lines as i32,
415+
}));
416+
}
407417
Update::Unfocus => {
408418
state.is_focused = false;
409419
state.drag_click = None;
@@ -577,6 +587,7 @@ where
577587

578588
enum Update {
579589
Click(mouse::Click),
590+
Scroll(f32),
580591
Unfocus,
581592
Release,
582593
Action(Action),
@@ -630,21 +641,16 @@ impl Update {
630641
mouse::Event::WheelScrolled { delta }
631642
if cursor.is_over(bounds) =>
632643
{
633-
action(Action::Scroll {
634-
lines: match delta {
635-
mouse::ScrollDelta::Lines { y, .. } => {
636-
if y.abs() > 0.0 {
637-
(y.signum() * -(y.abs() * 4.0).max(1.0))
638-
as i32
639-
} else {
640-
0
641-
}
642-
}
643-
mouse::ScrollDelta::Pixels { y, .. } => {
644-
(-y / 4.0) as i32
644+
Some(Update::Scroll(match delta {
645+
mouse::ScrollDelta::Lines { y, .. } => {
646+
if y.abs() > 0.0 {
647+
y.signum() * -(y.abs() * 4.0).max(1.0)
648+
} else {
649+
0.0
645650
}
646-
},
647-
})
651+
}
652+
mouse::ScrollDelta::Pixels { y, .. } => -y / 4.0,
653+
}))
648654
}
649655
_ => None,
650656
},

0 commit comments

Comments
 (0)