From f61c6c7f876e5aec5040e1f433b559dc7dea33a3 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Sat, 18 Jan 2025 12:52:55 +0100 Subject: [PATCH] fix: cancel when clicking outside of a palette instead of activating the current item --- src/tui/mode/overlay/palette.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tui/mode/overlay/palette.zig b/src/tui/mode/overlay/palette.zig index 239d95f..505346b 100644 --- a/src/tui/mode/overlay/palette.zig +++ b/src/tui/mode/overlay/palette.zig @@ -51,7 +51,10 @@ pub fn Create(options: type) type { const self: *Self = try allocator.create(Self); self.* = .{ .allocator = allocator, - .modal = try ModalBackground.create(*Self, allocator, tui.current().mainview, .{ .ctx = self }), + .modal = try ModalBackground.create(*Self, allocator, tui.current().mainview, .{ + .ctx = self, + .on_click = mouse_palette_menu_cancel, + }), .menu = try Menu.create(*Self, allocator, tui.current().mainview, .{ .ctx = self, .on_render = if (@hasDecl(options, "on_render_menu")) options.on_render_menu else on_render_menu, @@ -201,6 +204,10 @@ pub fn Create(options: type) type { self.start_query(0) catch {}; } + fn mouse_palette_menu_cancel(self: *Self, _: *ModalBackground.State(*Self)) void { + self.cmd("palette_menu_cancel", .{}) catch {}; + } + pub fn receive(self: *Self, _: tp.pid_ref, m: tp.message) error{Exit}!bool { var text: []const u8 = undefined;