@@ -200,8 +200,9 @@ fn (tv &TextView) mouse_move_locked(layout &Layout, mut e Event, mut w Window) {
200200 if ! w.has_animation (id_auto_scroll_animation) {
201201 w.animation_add (mut Animate{
202202 id: id_auto_scroll_animation
203- callback: fn [tv, id_focus, id_scroll_container] (mut w Window) {
204- tv.auto_scroll_cursor (id_focus, id_scroll_container, mut w)
203+ callback: fn [tv, id_focus, id_scroll_container] (mut an Animate, mut w Window) {
204+ tv.auto_scroll_cursor (id_focus, id_scroll_container, mut an, mut
205+ w)
205206 }
206207 delay: auto_scroll_delay
207208 repeat: true
@@ -261,7 +262,7 @@ fn (tv &TextView) mouse_up_locked(layout &Layout, mut e Event, mut w Window) {
261262// callback when the user drags to select text beyond the view boundaries. The function
262263// scrolls one line at a time (up or down) and updates the cursor position and selection
263264// range accordingly, providing smooth auto-scrolling behavior during drag selection.
264- fn (tv &TextView) auto_scroll_cursor (id_focus u32 , id_scroll_container u32 , mut w Window) {
265+ fn (tv &TextView) auto_scroll_cursor (id_focus u32 , id_scroll_container u32 , mut an Animate, mut w Window) {
265266 mut layout := w.layout.find_layout (fn [id_focus] (ly Layout) bool {
266267 return ly.shape.id_scroll == id_focus
267268 }) or { return }
@@ -318,6 +319,27 @@ fn (tv &TextView) auto_scroll_cursor(id_focus u32, id_scroll_container u32, mut
318319 }
319320
320321 scroll_cursor_into_view (mouse_cursor_pos, layout, mut w)
322+
323+ // Find the scroll container
324+ scroll_container := w.layout.find_layout (fn [id_scroll_container] (ly Layout) bool {
325+ return ly.shape.id_scroll == id_scroll_container
326+ }) or { return }
327+
328+ evs := event_relative_to (scroll_container.shape, e)
329+
330+ diff := match evs.mouse_y < 0 {
331+ true { - evs.mouse_y }
332+ else { evs.mouse_y - scroll_container.shape.height }
333+ }
334+
335+ lh := line_height (layout.shape)
336+ if diff > 2 * lh {
337+ an.delay = 30 * time.millisecond
338+ } else if diff > lh {
339+ an.delay = 80 * time.millisecond
340+ } else {
341+ an.delay = auto_scroll_delay
342+ }
321343}
322344
323345// cursor_pos_to_scroll_y calculates the vertical scroll offset needed to make a cursor
0 commit comments