fix: cancel when clicking outside of a palette instead of activating the current item

This commit is contained in:
CJ van den Berg 2025-01-18 12:52:55 +01:00
parent 0eec33c35e
commit f61c6c7f87
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -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;