fix(tui): reset drag context when invalidating the widget tree

This prevents a segfault if dragging and navigating at the same time.
This commit is contained in:
CJ van den Berg 2024-06-20 22:21:49 +02:00
parent ce9c5ea23d
commit 3ea039f41c
2 changed files with 8 additions and 0 deletions

View file

@ -166,6 +166,7 @@ const cmds = struct {
}
pub fn navigate(self: *Self, ctx: Ctx) tp.result {
tui.reset_drag_context();
const frame = tracy.initZone(@src(), .{ .name = "navigate" });
defer frame.deinit();
var file: ?[]const u8 = null;
@ -231,6 +232,7 @@ const cmds = struct {
}
pub fn open_help(self: *Self, _: Ctx) tp.result {
tui.reset_drag_context();
try self.create_editor();
try command.executeName("open_scratch_buffer", command.fmt(.{ "help.md", @embedFile("help.md") }));
tui.need_render();
@ -426,6 +428,7 @@ fn show_home_async(_: *Self) void {
}
fn create_home(self: *Self) tp.result {
tui.reset_drag_context();
if (self.editor) |_| return;
var home_widget = home.create(self.a, Widget.to(self)) catch |e| return tp.exit_error(e);
errdefer home_widget.deinit(self.a);

View file

@ -664,6 +664,11 @@ pub fn get_mode() []const u8 {
return if (current().input_mode) |m| m.name else "INI";
}
pub fn reset_drag_context() void {
const self = current();
self.drag_source = null;
}
pub fn need_render() void {
const self = current();
if (!(self.render_pending or self.frame_clock_running)) {