mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
input: binding set needs to clean up leader memory on manual put
This commit is contained in:

committed by
Mitchell Hashimoto

parent
2bf20ec32c
commit
bfb31c374e
@ -1007,18 +1007,26 @@ pub const Set = struct {
|
|||||||
|
|
||||||
const gop = try self.bindings.getOrPut(alloc, t);
|
const gop = try self.bindings.getOrPut(alloc, t);
|
||||||
|
|
||||||
// If we have an existing binding for this trigger, we have to
|
if (gop.found_existing) switch (gop.value_ptr.*) {
|
||||||
// update the reverse mapping to remove the old action.
|
// If we have a leader we need to clean up the memory
|
||||||
if (gop.found_existing) {
|
.leader => |s| {
|
||||||
const t_hash = t.hash();
|
s.deinit(alloc);
|
||||||
var it = self.reverse.iterator();
|
alloc.destroy(s);
|
||||||
while (it.next()) |reverse_entry| it: {
|
},
|
||||||
if (t_hash == reverse_entry.value_ptr.hash()) {
|
|
||||||
self.reverse.removeByPtr(reverse_entry.key_ptr);
|
// If we have an existing binding for this trigger, we have to
|
||||||
break :it;
|
// update the reverse mapping to remove the old action.
|
||||||
|
.action, .action_unconsumed => {
|
||||||
|
const t_hash = t.hash();
|
||||||
|
var it = self.reverse.iterator();
|
||||||
|
while (it.next()) |reverse_entry| it: {
|
||||||
|
if (t_hash == reverse_entry.value_ptr.hash()) {
|
||||||
|
self.reverse.removeByPtr(reverse_entry.key_ptr);
|
||||||
|
break :it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
gop.value_ptr.* = if (consumed) .{
|
gop.value_ptr.* = if (consumed) .{
|
||||||
.action = action,
|
.action = action,
|
||||||
@ -1617,6 +1625,26 @@ test "set: parseAndPut sequence preserves reverse mapping" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "set: put overwrites sequence" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s: Set = .{};
|
||||||
|
defer s.deinit(alloc);
|
||||||
|
|
||||||
|
try s.parseAndPut(alloc, "ctrl+a>b=new_window");
|
||||||
|
try s.put(alloc, .{
|
||||||
|
.mods = .{ .ctrl = true },
|
||||||
|
.key = .{ .translated = .a },
|
||||||
|
}, .{ .new_window = {} });
|
||||||
|
|
||||||
|
// Creates reverse mapping
|
||||||
|
{
|
||||||
|
const trigger = s.getTrigger(.{ .new_window = {} }).?;
|
||||||
|
try testing.expect(trigger.key.translated == .a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "set: maintains reverse mapping" {
|
test "set: maintains reverse mapping" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
Reference in New Issue
Block a user