diff options
Diffstat (limited to 'src/Query.zig')
| -rw-r--r-- | src/Query.zig | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/Query.zig b/src/Query.zig index 5fdfff2a..87c9d3bd 100644 --- a/src/Query.zig +++ b/src/Query.zig @@ -676,27 +676,20 @@ fn noteRows(p: *Pardes, id: usize, note: []const u8) void { setRows(p, rp, &out, &rows); } -/// One row: its text and its metadata, the path copied. +/// One row: its text and its metadata, the path and colours copied. fn writeRow(p: *Pardes, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row), text: []const u8, meta: locations.Row) !void { try out.appendSlice(p.gpa, text); try out.append(p.gpa, '\n'); - var m = meta; - m.path = try p.gpa.dupe(u8, meta.path); - errdefer p.gpa.free(m.path); // Coloured whole (zeros where nothing coloured it): the pane's syntax // pass then parses no fragment of it, per refill. const code = text[@min(meta.code_start, text.len)..]; - m.colors = if (meta.colors.len >= code.len) try p.gpa.dupe(u8, meta.colors[0..code.len]) else blk: { - const c = try p.gpa.alloc(u8, code.len); - @memset(c, 0); - @memcpy(c[0..meta.colors.len], meta.colors); - break :blk c; - }; - rows.append(p.gpa, m) catch |err| { - p.gpa.free(m.path); - p.gpa.free(m.colors); - return err; - }; + var m = meta; + if (meta.colors.len >= code.len) m.colors = meta.colors[0..code.len] else { + m.colors = try p.scratch.allocator().alloc(u8, code.len); + @memset(m.colors, 0); + @memcpy(m.colors[0..meta.colors.len], meta.colors); + } + try locations.appendRow(p.gpa, rows, m); } /// The rows made into the pane: line 1 as it is (the user's), then `out`, |
