@@ -102,6 +102,7 @@ pub const TabStopResult = struct {
102102pub const WrapBreak = struct {
103103 byte_offset : u32 ,
104104 char_offset : u32 ,
105+ col_offset : u32 ,
105106};
106107
107108pub const WrapBreakResult = struct {
@@ -190,6 +191,7 @@ pub fn findWrapBreaks(text: []const u8, result: *WrapBreakResult, width_method:
190191
191192 var pos : usize = 0 ;
192193 var char_offset : u32 = 0 ;
194+ var col_offset : u32 = 0 ;
193195 var prev_cp : ? u21 = null ; // Track previous codepoint for grapheme detection
194196 var break_state : uucode.grapheme.BreakState = .default ;
195197
@@ -242,12 +244,14 @@ pub fn findWrapBreaks(text: []const u8, result: *WrapBreakResult, width_method:
242244 try result .breaks .append (result .allocator , .{
243245 .byte_offset = @intCast (pos + bit_pos ),
244246 .char_offset = char_offset + @as (u32 , @intCast (bit_pos )),
247+ .col_offset = col_offset + @as (u32 , @intCast (bit_pos )),
245248 });
246249 bitmask &= bitmask - 1 ;
247250 }
248251
249252 pos += vector_len ;
250253 char_offset += vector_len ;
254+ col_offset += vector_len ;
251255 prev_cp = text [pos - 1 ]; // Last ASCII char
252256 continue ;
253257 }
@@ -270,11 +274,13 @@ pub fn findWrapBreaks(text: []const u8, result: *WrapBreakResult, width_method:
270274 try result .breaks .append (result .allocator , .{
271275 .byte_offset = @intCast (pos + i ),
272276 .char_offset = char_offset ,
277+ .col_offset = col_offset ,
273278 });
274279 }
275280 i += 1 ;
276281 if (is_break ) {
277282 char_offset += 1 ;
283+ col_offset += 1 ;
278284 }
279285 prev_cp = curr_cp ;
280286 } else {
@@ -292,11 +298,13 @@ pub fn findWrapBreaks(text: []const u8, result: *WrapBreakResult, width_method:
292298 try result .breaks .append (result .allocator , .{
293299 .byte_offset = @intCast (pos + i ),
294300 .char_offset = char_offset ,
301+ .col_offset = col_offset ,
295302 });
296303 }
297304 i += dec .len ;
298305 if (is_break ) {
299306 char_offset += 1 ;
307+ col_offset += eastAsianWidth (dec .cp );
300308 }
301309 prev_cp = dec .cp ;
302310 }
@@ -319,11 +327,13 @@ pub fn findWrapBreaks(text: []const u8, result: *WrapBreakResult, width_method:
319327 try result .breaks .append (result .allocator , .{
320328 .byte_offset = @intCast (i ),
321329 .char_offset = char_offset ,
330+ .col_offset = col_offset ,
322331 });
323332 }
324333 i += 1 ;
325334 if (is_break ) {
326335 char_offset += 1 ;
336+ col_offset += 1 ;
327337 }
328338 prev_cp = curr_cp ;
329339 } else {
@@ -339,11 +349,13 @@ pub fn findWrapBreaks(text: []const u8, result: *WrapBreakResult, width_method:
339349 try result .breaks .append (result .allocator , .{
340350 .byte_offset = @intCast (i ),
341351 .char_offset = char_offset ,
352+ .col_offset = col_offset ,
342353 });
343354 }
344355 i += dec .len ;
345356 if (is_break ) {
346357 char_offset += 1 ;
358+ col_offset += eastAsianWidth (dec .cp );
347359 }
348360 prev_cp = dec .cp ;
349361 }
0 commit comments