Skip to content

bug: mouse drag selection and double-click word select don't work in TextField #225

Description

@kolkov

Problem

Mouse drag selection and double-click word selection don't work in TextField, despite the selection model being fully implemented internally. The selection model (core/textfield/selection.go), rendering (all 4 theme painters), and keyboard selection (Shift+arrows, Ctrl+A) all work correctly. The gap is in the event dispatch layer.

What works: click to place cursor, Shift+arrows, Ctrl+Shift+arrows (word), Ctrl+A, typing, horizontal scroll.

What doesn't work: mouse drag to select, double-click to select word, Ctrl+C/V to OS clipboard.

Root Cause

Gap 1: MouseDrag never synthesized

app/event_bridge.go:34-38OnMouseMove always emits event.MouseMove, even when buttons are pressed. TextField's handleMouseDrag (core/textfield/event.go:49-50) listens for event.MouseDrag which is never dispatched.

Fix: In event_bridge.go, check pressedButtons != 0 during mouse move → emit MouseDrag instead of MouseMove. ~3 lines.

Gap 2: MouseDoubleClick never dispatched

event.MouseDoubleClick type exists (event/mouse.go:33-34). TextField handles it (event.go:52-53, handleDoubleClick selects word via wordBoundsAt()). But no component in the stack generates this event — no double-click timing detector exists in the event bridge, window, or platform layer.

Fix: Add click timing detector in event_bridge.go or app/window.go — two presses within ~400ms at similar position → MouseDoubleClick. Flutter: 300ms, Win32: 500ms. ~30 lines.

Gap 3: Clipboard is internal only

selection.go:9clipboard string is an in-memory field. copyToClipboard/pasteFromClipboard (lines 141-151) don't reach the OS clipboard. Ctrl+C/V work within the same widget instance only.

Fix: Wire to platform clipboard — gpucontext.ClipboardProvider interface or direct platform calls (Win32 SetClipboardData/GetClipboardText, macOS NSPasteboard, X11 XSetSelectionOwner, Wayland wl_data_source).

Enterprise References

Feature Flutter GTK4 Win32
Drag selection TextSelectionGestureDetector gtk_text_handle_drag WM_MOUSEMOVE + MK_LBUTTON
Double-click kDoubleTapTimeout = 300ms GDK_2BUTTON_PRESS WM_LBUTTONDBLCLK (500ms default)
Triple-click kDoubleTapTimeout chain GDK_3BUTTON_PRESS Manual detection
OS clipboard Clipboard.getData gtk_clipboard_get GetClipboardData

Implementation Priority

  1. MouseDrag synthesis (~3 LOC) — unblocks drag selection immediately
  2. Double-click detection (~30 LOC) — word selection
  3. OS clipboard (~100 LOC across platforms) — copy/paste interop
  4. Triple-click line select (~10 LOC) — nice-to-have

Metadata

Metadata

Assignees

Labels

area: widgetCore widget abstractions & interfacestype: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions