@@ -1499,10 +1499,9 @@ fn getPrevGraphemeStartWCWidth(text: []const u8, byte_offset: usize, tab_width:
14991499 if (byte_offset == 0 or text .len == 0 ) return null ;
15001500 if (byte_offset > text .len ) return null ;
15011501
1502- // Build a list of all codepoint positions
1503- var codepoint_positions = std .BoundedArray (struct { pos : usize , width : u32 }, 256 ).init (0 ) catch unreachable ;
1504-
15051502 var pos : usize = 0 ;
1503+ var last_result : ? PrevGraphemeResult = null ;
1504+
15061505 while (pos < byte_offset ) {
15071506 const b = text [pos ];
15081507 const curr_cp : u21 = if (b < 0x80 ) b else blk : {
@@ -1513,23 +1512,16 @@ fn getPrevGraphemeStartWCWidth(text: []const u8, byte_offset: usize, tab_width:
15131512 const cp_len : usize = if (b < 0x80 ) 1 else decodeUtf8Unchecked (text , pos ).len ;
15141513 const cp_width = charWidth (b , curr_cp , tab_width );
15151514
1516- codepoint_positions .appendAssumeCapacity (.{ .pos = pos , .width = cp_width });
1517- pos += cp_len ;
1518- }
1519-
1520- // Find the last non-zero-width codepoint before byte_offset
1521- var i : isize = @as (isize , @intCast (codepoint_positions .len )) - 1 ;
1522- while (i >= 0 ) : (i -= 1 ) {
1523- const idx = @as (usize , @intCast (i ));
1524- if (codepoint_positions .get (idx ).width > 0 ) {
1525- return .{
1526- .start_offset = codepoint_positions .get (idx ).pos ,
1527- .width = codepoint_positions .get (idx ).width ,
1515+ if (cp_width > 0 ) {
1516+ last_result = .{
1517+ .start_offset = pos ,
1518+ .width = cp_width ,
15281519 };
15291520 }
1521+ pos += cp_len ;
15301522 }
15311523
1532- return null ;
1524+ return last_result ;
15331525}
15341526
15351527/// Get previous grapheme start using Unicode grapheme cluster segmentation
0 commit comments