From fdda6ba1a492859425fe5577d3b159bfd4c845b0 Mon Sep 17 00:00:00 2001 From: reugenio Date: Sat, 20 Dec 2025 17:26:31 +0100 Subject: [PATCH] fix(autocomplete): Cursor igual que TextInput - altura completa + parpadeo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Altura del cursor: inner.h (toda la altura del campo, no 8px fijos) - Posición Y: inner.y (no centrado en el texto) - Parpadeo: usa CURSOR_BLINK_PERIOD_MS y CURSOR_IDLE_TIMEOUT_MS - Lógica idéntica a TextInput para consistencia visual --- src/widgets/autocomplete.zig | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/widgets/autocomplete.zig b/src/widgets/autocomplete.zig index b6a4238..a309470 100644 --- a/src/widgets/autocomplete.zig +++ b/src/widgets/autocomplete.zig @@ -375,12 +375,28 @@ pub fn autocompleteRect( ctx.pushCommand(Command.text(inner.x, text_y, config.placeholder, Style.Color.rgb(100, 100, 100))); } - // Draw cursor if focused + // Draw cursor if focused (same style as TextInput) if (is_focused and !config.disabled) { - // Use ctx.measureTextToCursor for accurate cursor positioning with variable-width fonts - const cursor_offset = ctx.measureTextToCursor(filter_text, state.cursor); - const cursor_x = inner.x + @as(i32, @intCast(cursor_offset)); - ctx.pushCommand(Command.rect(cursor_x, text_y, 2, char_height, Style.Color.rgb(200, 200, 200))); + // Cursor blink logic (identical to TextInput) + const cursor_visible = blk: { + if (ctx.current_time_ms == 0) break :blk true; + const idle_time = ctx.current_time_ms -| ctx.last_input_time_ms; + if (idle_time >= Context.CURSOR_IDLE_TIMEOUT_MS) { + // Idle: cursor always visible (solid, no blink) + break :blk true; + } else { + // Active: cursor blinks + break :blk (ctx.current_time_ms / Context.CURSOR_BLINK_PERIOD_MS) % 2 == 0; + } + }; + + if (cursor_visible) { + // Use ctx.measureTextToCursor for accurate cursor positioning with variable-width fonts + const cursor_offset = ctx.measureTextToCursor(filter_text, state.cursor); + const cursor_x = inner.x + @as(i32, @intCast(cursor_offset)); + // Full height cursor (inner.h), same as TextInput + ctx.pushCommand(Command.rect(cursor_x, inner.y, 2, inner.h, Style.Color.rgb(200, 200, 200))); + } } // Draw dropdown arrow