Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: text wrapping boundary cases #1879

Merged
merged 2 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-impalas-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g-lite': patch
---

fix: text wrapping boundary cases
12 changes: 6 additions & 6 deletions packages/g-lite/src/services/TextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export class TextService {
textCharIndex += 1;
txt += chars[textCharIndex];
}
while (calcWidth(txt) > widthThreshold) {
while (calcWidth(txt) > widthThreshold && textCharIndex > 0) {
textCharIndex -= 1;
txt = txt.slice(0, -1);
}
Expand Down Expand Up @@ -436,7 +436,7 @@ export class TextService {
parsedStyle.isOverflowing = true;

if (i < chars.length - 1) {
appendEllipsis(currentLineIndex, i);
appendEllipsis(currentLineIndex, i - 1);
}

break;
Expand All @@ -452,17 +452,17 @@ export class TextService {
if (currentLineWidth > 0 && currentLineWidth + charWidth > maxWidth) {
const result = findCharIndexClosestWidthThreshold(
lines[currentLineIndex],
i,
i - 1,
maxWidth,
);
if (result.textCharIndex !== i) {
if (result.textCharIndex !== i - 1) {
lines[currentLineIndex] = result.txt;

if (result.textCharIndex === chars.length - 1) {
break;
}

i = result.textCharIndex;
i = result.textCharIndex + 1;
char = chars[i];
prevChar = chars[i - 1];
nextChar = chars[i + 1];
Expand All @@ -472,7 +472,7 @@ export class TextService {
if (currentLineIndex + 1 >= maxLines) {
parsedStyle.isOverflowing = true;

appendEllipsis(currentLineIndex, i);
appendEllipsis(currentLineIndex, i - 1);

break;
}
Expand Down
Loading