this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

TextView: fix cols when appending to a buffer

If appending to a buffer through writer for example, the cols may not be
correct if the writes don't end up in a newline (\n). Fix this by
keeping track of the cols of previous append.

authored by

Jari Vetoniemi and committed by
Tim Culverhouse
71b8ecc7 ef028bfe

+4 -1
+4 -1
src/widgets/TextView.zig
··· 49 49 style_map: StyleMap = .{}, 50 50 rows: usize = 0, 51 51 cols: usize = 0, 52 + // used when appending to a buffer 53 + last_cols: usize = 0, 52 54 53 55 pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void { 54 56 self.style_map.deinit(allocator); ··· 73 75 74 76 /// Appends content to the buffer. 75 77 pub fn append(self: *@This(), allocator: std.mem.Allocator, content: Content) !void { 76 - var cols: usize = 0; 78 + var cols: usize = self.last_cols; 77 79 var iter = grapheme.Iterator.init(content.bytes, content.gd); 78 80 const dw: DisplayWidth = .{ .data = content.wd }; 79 81 while (iter.next()) |g| { ··· 90 92 cols +|= dw.strWidth(cluster); 91 93 } 92 94 try self.content.appendSlice(allocator, content.bytes); 95 + self.last_cols = cols; 93 96 self.cols = @max(self.cols, cols); 94 97 self.rows +|= std.mem.count(u8, content.bytes, "\n"); 95 98 }