Skip to content

Commit

Permalink
fix: text wrapping boundary cases (#1879)
Browse files Browse the repository at this point in the history
* fix: text wrapping boundary cases

* chore: remove log
  • Loading branch information
wang1212 authored Dec 26, 2024
1 parent 7ce64f1 commit d5e7a9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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

0 comments on commit d5e7a9f

Please sign in to comment.