mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
input: Binding.Set.clone handles leaders
This commit is contained in:

committed by
Mitchell Hashimoto

parent
bfb31c374e
commit
9944f5d34d
@ -3317,13 +3317,7 @@ pub const Keybinds = struct {
|
|||||||
|
|
||||||
/// Deep copy of the struct. Required by Config.
|
/// Deep copy of the struct. Required by Config.
|
||||||
pub fn clone(self: *const Keybinds, alloc: Allocator) !Keybinds {
|
pub fn clone(self: *const Keybinds, alloc: Allocator) !Keybinds {
|
||||||
// TODO: leaders
|
return .{ .set = try self.set.clone(alloc) };
|
||||||
return .{
|
|
||||||
.set = .{
|
|
||||||
.bindings = try self.set.bindings.clone(alloc),
|
|
||||||
.reverse = try self.set.reverse.clone(alloc),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compare if two of our value are requal. Required by Config.
|
/// Compare if two of our value are requal. Required by Config.
|
||||||
|
@ -1089,6 +1089,32 @@ pub const Set = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deep clone the set.
|
||||||
|
pub fn clone(self: *const Set, alloc: Allocator) !Set {
|
||||||
|
var result: Set = .{
|
||||||
|
.bindings = try self.bindings.clone(alloc),
|
||||||
|
.reverse = try self.reverse.clone(alloc),
|
||||||
|
};
|
||||||
|
|
||||||
|
// If we have any leaders we need to clone them.
|
||||||
|
var it = result.bindings.iterator();
|
||||||
|
while (it.next()) |entry| switch (entry.value_ptr.*) {
|
||||||
|
// No data to clone
|
||||||
|
.action, .action_unconsumed => {},
|
||||||
|
|
||||||
|
// Must be deep cloned.
|
||||||
|
.leader => |*s| {
|
||||||
|
const ptr = try alloc.create(Set);
|
||||||
|
errdefer alloc.destroy(ptr);
|
||||||
|
ptr.* = try s.*.clone(alloc);
|
||||||
|
errdefer ptr.deinit(alloc);
|
||||||
|
s.* = ptr;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// The hash map context for the set. This defines how the hash map
|
/// The hash map context for the set. This defines how the hash map
|
||||||
/// gets the hash key and checks for equality.
|
/// gets the hash key and checks for equality.
|
||||||
fn Context(comptime KeyType: type) type {
|
fn Context(comptime KeyType: type) type {
|
||||||
|
Reference in New Issue
Block a user