@@ -10,7 +10,9 @@ import math
1010import time
1111
1212const id_auto_scroll_animation = 'auto_scroll_animation'
13- const auto_scroll_delay = 150 * time.millisecond
13+ const auto_scroll_slow = 150 * time.millisecond
14+ const auto_scroll_medium = 80 * time.millisecond
15+ const auto_scroll_fast = 30 * time.millisecond
1416
1517// TextMode controls how a text view renders text.
1618pub enum TextMode as u8 {
@@ -130,9 +132,6 @@ pub fn text(cfg TextView) View {
130132// It sets up mouse locking for drag selection updates and positions the text cursor
131133// based on the click coordinates.
132134fn (tv &TextView) on_click (layout & Layout, mut e Event, mut w Window) {
133- if w.is_focus (layout.shape.id_focus) {
134- w.set_mouse_cursor_ibeam ()
135- }
136135 if e.mouse_button == .left && w.is_focus (layout.shape.id_focus) {
137136 id_focus := layout.shape.id_focus
138137 cursor_pos := tv.mouse_cursor_pos (layout.shape, e, mut w)
@@ -177,9 +176,6 @@ fn (tv &TextView) on_click(layout &Layout, mut e Event, mut w Window) {
177176// It updates the text selection range based on the current mouse position relative to the
178177// starting cursor position.
179178fn (tv &TextView) mouse_move_locked (layout & Layout, mut e Event, mut w Window) {
180- if w.is_focus (layout.shape.id_focus) {
181- w.set_mouse_cursor_ibeam ()
182- }
183179 // mouse_move events don't have mouse button info. Use context.
184180 if w.ui.mouse_buttons == .left && w.is_focus (layout.shape.id_focus) {
185181 if tv.placeholder_active {
@@ -204,7 +200,7 @@ fn (tv &TextView) mouse_move_locked(layout &Layout, mut e Event, mut w Window) {
204200 tv.auto_scroll_cursor (id_focus, id_scroll_container, mut an, mut
205201 w)
206202 }
207- delay: auto_scroll_delay
203+ delay: auto_scroll_slow
208204 repeat: true
209205 })
210206 }
@@ -233,26 +229,9 @@ fn (tv &TextView) mouse_move_locked(layout &Layout, mut e Event, mut w Window) {
233229}
234230
235231// mouse_up_locked handles mouse up events while the mouse is locked (after a drag selection).
236- // It finalizes the cursor position based on the mouse release location, updates the view state
237- // with the new cursor position, and ensures the cursor is scrolled into view.
238232fn (tv &TextView) mouse_up_locked (layout & Layout, mut e Event, mut w Window) {
239233 if w.is_focus (layout.shape.id_focus) {
240- w.set_mouse_cursor_ibeam ()
241234 w.remove_animation (id_auto_scroll_animation)
242-
243- // determine the cursor position from the mouse position
244- ev := event_relative_to (layout.shape, e)
245- mouse_cursor_pos := tv.mouse_cursor_pos (layout.shape, ev, mut w)
246-
247- // update the view state with the new mouse_cursor_pos
248- input_state := w.view_state.input_state[layout.shape.id_focus]
249- w.view_state.input_state[layout.shape.id_focus] = InputState{
250- ...input_state
251- cursor_pos: mouse_cursor_pos
252- cursor_offset: - 1
253- }
254-
255- scroll_cursor_into_view (mouse_cursor_pos, layout, mut w)
256235 e.is_handled = true
257236 }
258237}
@@ -320,25 +299,28 @@ fn (tv &TextView) auto_scroll_cursor(id_focus u32, id_scroll_container u32, mut
320299
321300 scroll_cursor_into_view (mouse_cursor_pos, layout, mut w)
322301
302+ // Decide how fast the scroll animation should be based on the distance
303+ // the mouse is outside the scroll container view.
304+ //
323305 // Find the scroll container
324306 scroll_container := w.layout.find_layout (fn [id_scroll_container] (ly Layout) bool {
325307 return ly.shape.id_scroll == id_scroll_container
326308 }) or { return }
327309
328310 evs := event_relative_to (scroll_container.shape, e)
329311
330- diff := match evs.mouse_y < 0 {
312+ distance := match evs.mouse_y < 0 {
331313 true { - evs.mouse_y }
332314 else { evs.mouse_y - scroll_container.shape.height }
333315 }
334316
335317 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
318+ if distance > 2 * lh {
319+ an.delay = auto_scroll_fast
320+ } else if distance > lh {
321+ an.delay = auto_scroll_medium
340322 } else {
341- an.delay = auto_scroll_delay
323+ an.delay = auto_scroll_slow
342324 }
343325}
344326
0 commit comments