From 37ecd5cdef0c2b4a3a23575e63a47bcea4255ed9 Mon Sep 17 00:00:00 2001 From: egrs Date: Wed, 18 Feb 2026 13:47:09 +0100 Subject: [PATCH] use textarea.innerInsert for selection-aware text insertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both insertText() and handleKeydown() were manually concatenating text to the textarea value, ignoring the current selection range. This uses the existing innerInsert() method which correctly handles full, partial, and no-selection states — matching the Input element behavior. --- src/browser/Page.zig | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/browser/Page.zig b/src/browser/Page.zig index 40b73618..dce19037 100644 --- a/src/browser/Page.zig +++ b/src/browser/Page.zig @@ -3113,9 +3113,7 @@ pub fn handleKeydown(self: *Page, target: *Node, event: *Event) !void { else return ; // zig fmt: on - const current_value = textarea.getValue(); - const new_value = try std.mem.concat(self.arena, u8, &.{ current_value, append }); - return textarea.setValue(new_value, self); + return textarea.innerInsert(append, self); } } @@ -3200,13 +3198,11 @@ pub fn insertText(self: *Page, v: []const u8) !void { return; } - try input.innerInsert(v, self); + return input.innerInsert(v, self); } if (html_element.is(Element.Html.TextArea)) |textarea| { - const current_value = textarea.getValue(); - const new_value = try std.mem.concat(self.arena, u8, &.{ current_value, v }); - return textarea.setValue(new_value, self); + return textarea.innerInsert(v, self); } }