[Bug Report]: getBytesLength counts every character as uppercase when a word has one capital, and snapToGrid never snaps to 0
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, typescript
- Domain
- frontend
Research direction
Two small bugs in packages/core: the getBytesLength loop in src/util/edge.ts (~L809) tests word.match(/[A-Z]/) where it should test the current character c, and snapToGrid in src/util/geometry.ts (~L9) uses || point, which wrongly returns the raw value when the snapped result is 0. Also check the if (nodeX && nodeY) guard in GraphModel.ts getModelAfterSnapToGrid. Start by running the reproduction script from the issue; done means the expected outputs listed there ([0, 0, 10, 10], 7.5 and 17.5 byte lengths) and the existing util tests still pass.
Written by the indexing model from the issue text.
Description
What happened?
Two utility bugs in @logicflow/core affect default text sizing and grid snapping:
-
getBytesLengthchecks the whole string instead of the current character. Inpackages/core/src/util/edge.ts#L809, the loop readsconst c = word.charCodeAt(i)but testsif (word.match(/[A-Z]/)), so a single capital letter gives every character inwordweight1.5.getSvgTextSize(edge label background<rect>inLineText) andgetSvgTextWidthHeight(TextNodeModel.width) both call it:- Lowercase ASCII characters (weight
1) count as1.5, making'Approve'50% wider than'approve'(75vs51atfontSize: 12). - CJK characters (weight
2) also drop to1.5, so prepending'A'to'网关审批流程节点'shrinks the computed width from99to87and the text overflows its box.
- Lowercase ASCII characters (weight
-
snapToGridskips0. Inpackages/core/src/util/geometry.ts#L9,gridSize * Math.round(point / gridSize) || pointfalls back topointwhenever the snapped coordinate is0(|point| < gridSize / 2). WhensnapGrid: true, nodes dragged, dropped, or added nearx = 0ory = 0keep their raw coordinate instead of snapping to0(andgetModelAfterSnapToGridinGraphModel.tsalso guards withif (nodeX && nodeY), skipping both axes when either coordinate is0).
Reproduction (npm i @logicflow/[email protected] && node repro.js, Node v26.13.0):
const {
snapToGrid,
getBytesLength,
getSvgTextSize,
getSvgTextWidthHeight,
} = require("@logicflow/core");
console.log([4, -4, 6, 14].map((v) => snapToGrid(v, 10, true)));
console.log(getBytesLength("approve"), getBytesLength("Approve"));
console.log(
getSvgTextSize({ rows: ["approve"], rowsLength: 1, fontSize: 12 }).width,
getSvgTextSize({ rows: ["Approve"], rowsLength: 1, fontSize: 12 }).width,
);
console.log(getBytesLength("网关审批流程节点"), getBytesLength("A网关审批流程节点"));
console.log(
getSvgTextWidthHeight({ rows: ["网关审批流程节点"], rowsLength: 1, fontSize: 12 }).width,
getSvgTextWidthHeight({ rows: ["A网关审批流程节点"], rowsLength: 1, fontSize: 12 }).width,
);
Actual output:
[ 4, -4, 10, 10 ]
7 10.5
51 75
16 13.5
99 87
Expected output:
snapToGridsnaps4and-4to0([ 0, 0, 10, 10 ]).getBytesLengthtests characteri(c >= 0x41 && c <= 0x5a), giving7.5for"Approve"(width51) and17.5for"A网关审批流程节点"(width111).
Core Version
2.2.5 (also verified on master d60a216)
Extension Version
2.3.1 (not required to reproduce)
Engine Version
No response
What browsers are you seeing the problem on?
Chrome
Credit: https://ucsbplse.github.io/
- Dominant language
- TypeScript
- Stars
- 11.8k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from didi/LogicFlow
-
[Bug Report]: resize改变画布尺寸未完全生效Possibly taken @dvd233 claimed this 70 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
[Bug Report]: Cannot access '{default export}' before initializationPossibly taken @dvd233 claimed this 42 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 54/100
-
[Bug Report]: 框选引用冲突Uncaught TypeError: dynamicGroup_1.getGroupByNodeId is not a functionMay be free again @Wang-Yi-Teng claimed this 117 days ago, and no pull request is open. Open
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
bug done
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neavo/LinguaGacha#1124 ·
Maintainers usually reply within 1 day
-
[fullsend] E2E: backstage-microsoft-auth — catalogQuery missing error handler for network errorsPossibly taken @fullsend-ai-coder claimed this today. Opene2e-failure ready-to-code
Difficulty 2/5 Under an hour Newbie friendliness 78/100
redhat-developer/rhdh-plugin-export-overlays#4821 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
brylie/mission-island#225 ·
Maintainers usually reply within 1 day
-
enhancement from-app needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
nightly-labs/openbot#14986 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
google-gemini/gemini-cli#30412 · 1 comment ·
Maintainers usually reply within 1 day