mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-24 20:45:56 +03:00
[PR #610] [CLOSED] fix(core): use byte offset for line_starts in text wrap #658
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#658
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/anomalyco/opentui/pull/610
Author: @zenyr
Created: 2/1/2026
Status: ❌ Closed
Base:
main← Head:fix/255-line-starts-byte-offset📝 Commits (10+)
841364cfix(core): use byte offset for line_starts in text wrap4f2e8d1test(core): add no-wrap byte offset test for CJK text00336ebfix(core): use byte offset for line_starts in no-wrap mode089f334refactor(core): use proactive byte offset tracking in no-wrap modee344f44perf(core): store byte_start/byte_len in VirtualChunk76b11a4test(text-buffer-view): add tests for CJK byte offset handling2823590fix: recompute byte offsetsa3123a6Merge branch 'main' into fix/255-line-starts-byte-offsetd241b35add word split bug repro8f6f30bMerge branch 'main' into fix/255-line-starts-byte-offset📊 Changes
3 files changed (+175 additions, -17 deletions)
View changed files
📝
packages/core/src/text-buffer-view.test.ts(+38 -0)📝
packages/core/src/zig/tests/text-buffer-view_test.zig(+31 -0)📝
packages/core/src/zig/text-buffer-view.zig(+106 -17)📄 Description
Summary
lineInfo.lineStartsto return byte offsets instead of column offsetsFixes #609
Changes
byte_offsettracking toVirtualLineand wrap context intext-buffer-view.zigcached_line_startsto use byte position instead of char/column positionTest
Design Considerations
Alternatives Considered
lineInfoaccess — defeats caching purposecached_line_startswithoutVirtualLinefieldcommitVirtualLine, harder to maintainChosen approach: Track
byte_offsetduring wrap (O(1) amortized). Memory overhead is ~4 bytes per wrapped line (~80KB for 10K lines), which is acceptable.Relation to Prior Work
VirtualLinestructure withchar_offset. This PR builds on that by addingbyte_offsetalongside it.col_offsetinWrapBreak. Different problem — this PR fixeslineStartsreturn values, not boundary calculation.Both prior PRs left
cached_line_startsusing character/column offsets, which corrupts multi-byte characters when used for slicing.Known Limitation
The no-wrap code path still uses
char_offsetforlineStarts. This is out of scope for this PR, as wrapping is the primary use case forlineStarts.cc: @DonKongPaPa @kskang @soomtong @stefanahman — you showed interest in #255; this PR addresses a remaining edge case with line boundary handling. Feedback welcome!
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.