From df76d2da1b3bc683b09f2117d621e58d48674bfb Mon Sep 17 00:00:00 2001 From: ITR Date: Sat, 7 Sep 2024 22:22:28 +0200 Subject: [PATCH] Added ctrl+a to select all text in a text-box --- src/gui/components/TextInput.zig | 8 ++++++++ src/gui/gui.zig | 5 +++++ src/main.zig | 1 + 3 files changed, 14 insertions(+) diff --git a/src/gui/components/TextInput.zig b/src/gui/components/TextInput.zig index a5eb31e9..9dea21c8 100644 --- a/src/gui/components/TextInput.zig +++ b/src/gui/components/TextInput.zig @@ -387,6 +387,14 @@ pub fn inputCharacter(self: *TextInput, character: u21) void { } } +pub fn selectAll(self: *TextInput, mods: main.Window.Key.Modifiers) void { + if(mods.control) { + self.selectionStart = 0; + self.cursor = @intCast(self.currentString.items.len); + self.ensureCursorVisibility(); + } +} + pub fn copy(self: *TextInput, mods: main.Window.Key.Modifiers) void { if(mods.control) { if(self.cursor) |cursor| { diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 224831f5..001d3fc4 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -425,6 +425,11 @@ pub const textCallbacks = struct { current.deleteRight(mods); } } + pub fn selectAll(mods: main.Window.Key.Modifiers) void { + if(selectedTextInput) |current| { + current.selectAll(mods); + } + } pub fn copy(mods: main.Window.Key.Modifiers) void { if(selectedTextInput) |current| { current.copy(mods); diff --git a/src/main.zig b/src/main.zig index 287e0f50..05610b0a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -335,6 +335,7 @@ pub const KeyBoard = struct { // MARK: KeyBoard .{.name = "textGotoEnd", .key = c.GLFW_KEY_END, .repeatAction = &gui.textCallbacks.gotoEnd}, .{.name = "textDeleteLeft", .key = c.GLFW_KEY_BACKSPACE, .repeatAction = &gui.textCallbacks.deleteLeft}, .{.name = "textDeleteRight", .key = c.GLFW_KEY_DELETE, .repeatAction = &gui.textCallbacks.deleteRight}, + .{.name = "textSelectAll", .key = c.GLFW_KEY_A, .repeatAction = &gui.textCallbacks.selectAll}, .{.name = "textCopy", .key = c.GLFW_KEY_C, .repeatAction = &gui.textCallbacks.copy}, .{.name = "textPaste", .key = c.GLFW_KEY_V, .repeatAction = &gui.textCallbacks.paste}, .{.name = "textCut", .key = c.GLFW_KEY_X, .repeatAction = &gui.textCallbacks.cut},