Re: Synedit wordwrap
Follow-up: found two more bugs in TLazSynEditLineWrapPlugin.CalculateNextBreak (syneditwrappedview.pp) that corrupt wrapped lines containing multi-byte UTF-8 characters (e.g. Japanese text, or wide symbols like ● / ■). Both are in the single-character fallback loop used when a "word" doesn't fit the available width (which is basically every line break in CJK text, since there are no ASCII break chars).
Bug 1 – negative remaining width splits a UTF-8 sequence:
When the first (too-wide) character is force-included via the Result = ALogStartFrom escape hatch, AMaxWidth can go negative. On the next byte (a UTF-8 continuation byte, width 0), the check CurCharPhysWidth <= AMaxWidth becomes 0 <= (negative) = False, so the loop stops mid-character, leaving an orphan continuation byte at the start of the next subline (renders as "?").
Bug 2 – wrong array index on subsequent wrapped lines:
PhysWidthPtr := @PhysCharWidths[0]; // should be [ALogStartFrom]
This resets the width lookup to the start of the whole line instead of the current subline's position, so wrap decisions for every subline after the first are made using the widths of unrelated characters earlier in the line. Since CJK text has almost no ASCII break chars, this fires on nearly every wrapped line, causing widespread garbling.
Fix (both in the same function):if Result = ALogStartFrom then begin
PhysWidthPtr := @PhysCharWidths[ALogStartFrom]; // was [0]
ALine := LastGoodPos;
while ALine^ <> #0 do begin
CurCharPhysWidth := PhysWidthPtr^ and PCWMask;
if (CurCharPhysWidth <= AMaxWidth) or (Result = ALogStartFrom)
or (CurCharPhysWidth = 0) then begin // always sweep in continuation bytes
inc(ALine);
inc(PhysWidthPtr);
inc(Result);
dec(AMaxWidth, CurCharPhysWidth);
end
else
break;
end;
end;
Screenshots attached: before the fix (widespread "?" corruption) and after (bug 2 fixed — the "?" garbling is gone; a separate, unrelated rendering artifact remains where the character immediately after a full-width symbol like ●/■ loses its left half — this looks like a pre-existing SynEdit character-painting issue unrelated to wrapping, reproducible even with WordWrap off).