this repo has no description
13
fork

Configure Feed

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

vxfw(RichText): fix softwrap of long words

The trimmed_width calculation of softwrapped long words was incorrect.
Fix the calculation and add a test for the case.

+32 -1
+32 -1
src/vxfw/RichText.zig
··· 288 288 if (cur_width + next_width > max_width) { 289 289 // Trim the word to see if it can fit on a line by itself 290 290 const trimmed = trimWSPLeft(word); 291 - const trimmed_width = next_width - trimmed.len; 291 + // New width is the previous width minus the number of cells we trimmed because we 292 + // are only trimming cells that would have been 1 wide (' ' and '\t' both measure as 293 + // 1 wide) 294 + const trimmed_width = next_width -| (word.len - trimmed.len); 292 295 if (trimmed_width > max_width) { 293 296 // Won't fit on line by itself, so fit as much on this line as we can 294 297 for (word) |cell| { ··· 377 380 // The last character will be an ellipsis 378 381 try std.testing.expectEqualStrings("…", surface.buffer[surface.buffer.len - 1].char.grapheme); 379 382 } 383 + } 384 + 385 + test "long word wrapping" { 386 + var rich_text: RichText = .{ 387 + .text = &.{ 388 + .{ .text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, 389 + }, 390 + }; 391 + 392 + const rich_widget = rich_text.widget(); 393 + 394 + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); 395 + defer arena.deinit(); 396 + const ucd = try vaxis.Unicode.init(arena.allocator()); 397 + vxfw.DrawContext.init(&ucd, .unicode); 398 + 399 + const len = rich_text.text[0].text.len; 400 + const width: u16 = 8; 401 + 402 + const ctx: vxfw.DrawContext = .{ 403 + .arena = arena.allocator(), 404 + .min = .{}, 405 + .max = .{ .width = width, .height = null }, 406 + }; 407 + 408 + const surface = try rich_widget.draw(ctx); 409 + // Height should be length / width 410 + try std.testing.expectEqual(len / width, surface.size.height); 380 411 } 381 412 382 413 test "refAllDecls" {