mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #2828 from ghostty-org/push-nqtkytsrpxwv
config: implement `clone` for RepeatableLink
This commit is contained in:
@ -4610,17 +4610,33 @@ pub const RepeatableLink = struct {
|
||||
}
|
||||
|
||||
/// Deep copy of the struct. Required by Config.
|
||||
pub fn clone(self: *const Self, alloc: Allocator) error{}!Self {
|
||||
_ = self;
|
||||
_ = alloc;
|
||||
return .{};
|
||||
pub fn clone(
|
||||
self: *const Self,
|
||||
alloc: Allocator,
|
||||
) Allocator.Error!Self {
|
||||
// Note: we don't do any errdefers below since the allocation
|
||||
// is expected to be arena allocated.
|
||||
|
||||
var list = try std.ArrayListUnmanaged(inputpkg.Link).initCapacity(
|
||||
alloc,
|
||||
self.links.items.len,
|
||||
);
|
||||
for (self.links.items) |item| {
|
||||
const copy = try item.clone(alloc);
|
||||
list.appendAssumeCapacity(copy);
|
||||
}
|
||||
|
||||
return .{ .links = list };
|
||||
}
|
||||
|
||||
/// Compare if two of our value are requal. Required by Config.
|
||||
pub fn equal(self: Self, other: Self) bool {
|
||||
_ = self;
|
||||
_ = other;
|
||||
return true;
|
||||
const itemsA = self.links.items;
|
||||
const itemsB = other.links.items;
|
||||
if (itemsA.len != itemsB.len) return false;
|
||||
for (itemsA, itemsB) |*a, *b| {
|
||||
if (!a.equal(b)) return false;
|
||||
} else return true;
|
||||
}
|
||||
|
||||
/// Used by Formatter
|
||||
|
@ -4,6 +4,8 @@
|
||||
//! action types.
|
||||
const Link = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const oni = @import("oniguruma");
|
||||
const Mods = @import("key.zig").Mods;
|
||||
|
||||
@ -59,3 +61,19 @@ pub fn oniRegex(self: *const Link) !oni.Regex {
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
/// Deep clone the link.
|
||||
pub fn clone(self: *const Link, alloc: Allocator) Allocator.Error!Link {
|
||||
return .{
|
||||
.regex = try alloc.dupe(u8, self.regex),
|
||||
.action = self.action,
|
||||
.highlight = self.highlight,
|
||||
};
|
||||
}
|
||||
|
||||
/// Check if two links are equal.
|
||||
pub fn equal(self: *const Link, other: *const Link) bool {
|
||||
return std.meta.eql(self.action, other.action) and
|
||||
std.meta.eql(self.highlight, other.highlight) and
|
||||
std.mem.eql(u8, self.regex, other.regex);
|
||||
}
|
||||
|
Reference in New Issue
Block a user