From 01da6f17ed30ba3754565ef3bcba587c697b458b Mon Sep 17 00:00:00 2001 From: fizzy pop-os-claude-2 Date: Wed, 11 Nov 2026 10:08:51 -0600 Subject: [PATCH] core: the text widgets end a touch frame the same way Signed-off-by: fizzy pop-os-claude-2 --- core/widgets/SelectableText.zig | 25 ++++++++++++++++--------- core/widgets/TextEntry.zig | 9 +-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/core/widgets/SelectableText.zig b/core/widgets/SelectableText.zig index 22b644cc3..d47c2bd1a 100644 --- a/core/widgets/SelectableText.zig +++ b/core/widgets/SelectableText.zig @@ -35,12 +35,12 @@ hold: *TouchHold, style: SelectionControls.Style, /// Starts the layout and reads this frame's touch events. Call `deinit` on the result, as for `dvui.textLayout`. -pub fn init(src: std.builtin.SourceLocation, init_opts: dvui.TextLayoutWidget.InitOptions, opts: dvui.Options) SelectableText { +pub fn init(src: std.lang.SourceLocation, init_opts: dvui.TextLayoutWidget.InitOptions, opts: dvui.Options) SelectableText { return initStyled(src, init_opts, opts, .{}); } /// `init`, with the selection menu drawn in `style`. -pub fn initStyled(src: std.builtin.SourceLocation, init_opts: dvui.TextLayoutWidget.InitOptions, opts: dvui.Options, style: SelectionControls.Style) SelectableText { +pub fn initStyled(src: std.lang.SourceLocation, init_opts: dvui.TextLayoutWidget.InitOptions, opts: dvui.Options, style: SelectionControls.Style) SelectableText { var tl_opts = init_opts; tl_opts.touch_edit_just_focused = false; const unhandled = touch_press.unhandledPresses(); @@ -116,13 +116,7 @@ fn processTouch(self: SelectableText, unhandled: touch_press.Presses) void { else => {}, } } - // A press the layout did not take, or a drag it let go of, is not a hold. - if (hold.armed and !hold.fired and !dvui.captured(tl.data().id)) hold.cancel(); - - if (hold.due(dvui.frameTimeNS())) selectWordAt(tl, tl.data().id, hold.x, hold.y); - if (hold.remaining(dvui.frameTimeNS())) |ns| { - dvui.timer(tl.data().id, @intCast(@divTrunc(ns, std.time.ns_per_us) + 1)); - } + _ = endHold(hold, tl, tl.data().id); } /// Selects the word under the physical point (`x`, `y`) of `tl` and shows its handles and menu. @@ -137,6 +131,19 @@ pub fn selectWordAt(tl: *dvui.TextLayoutWidget, focus_id: dvui.Id, x: f32, y: f3 dvui.refresh(null, @src(), tl.data().id); } +/// Call after a frame's touch events. Drops a hold whose press `tl` does not capture (a press it +/// did not take, or a drag it let go of); when the hold is due, selects the word under it with +/// `focus_id` focused and returns true. Asks dvui for a frame when the hold will be due. +pub fn endHold(hold: *TouchHold, tl: *dvui.TextLayoutWidget, focus_id: dvui.Id) bool { + if (hold.armed and !hold.fired and !dvui.captured(tl.data().id)) hold.cancel(); + const fired = hold.due(dvui.frameTimeNS()); + if (fired) selectWordAt(tl, focus_id, hold.x, hold.y); + if (hold.remaining(dvui.frameTimeNS())) |ns| { + dvui.timer(tl.data().id, @intCast(@divTrunc(ns, std.time.ns_per_us) + 1)); + } + return fired; +} + fn clear(tl: *dvui.TextLayoutWidget) void { tl.selection.start = 0; tl.selection.end = 0; diff --git a/core/widgets/TextEntry.zig b/core/widgets/TextEntry.zig index c35b0cfc0..e2707a7f7 100644 --- a/core/widgets/TextEntry.zig +++ b/core/widgets/TextEntry.zig @@ -232,14 +232,7 @@ fn processTouch(self: TextEntry, unhandled: touch.Presses, touch_editing: bool) else => {}, } } - if (hold.armed and !hold.fired and !dvui.captured(tl.data().id)) hold.cancel(); - if (hold.due(dvui.frameTimeNS())) { - SelectableText.selectWordAt(tl, self.entry.data().id, hold.x, hold.y); - placed = true; - } - if (hold.remaining(dvui.frameTimeNS())) |ns| { - dvui.timer(tl.data().id, @intCast(@divTrunc(ns, std.time.ns_per_us) + 1)); - } + if (SelectableText.endHold(hold, tl, self.entry.data().id)) placed = true; tl.state.te_first = false; tl.state.te_focus_on_touchdown = false; return placed;