[Bug Report]: getBytesLength counts every character as uppercase when a word has one capital, and snapToGrid never snaps to 0

Aperta Adatta ai principianti
#2,434 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@qq2514568380 ci sta già lavorando.

Dal 17/11/2026.

  • #2435 di @qq2514568380 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
frontend

Direzione di ricerca

Due piccoli bug in packages/core: il ciclo getBytesLength in src/util/edge.ts (~L809) verifica word.match(/[A-Z]/) mentre dovrebbe verificare il carattere corrente c, e snapToGrid in src/util/geometry.ts (~L9) usa || point, che restituisce erroneamente il valore grezzo quando il risultato allineato è 0. Controlla anche la guardia if (nodeX && nodeY) in GraphModel.ts all'interno di getModelAfterSnapToGrid. Inizia eseguendo lo script di riproduzione dell'issue. Il lavoro è completato quando si ottengono gli output attesi elencati lì ([0, 0, 10, 10], lunghezze in byte 7.5 e 17.5) e i test esistenti delle utility continuano a passare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

What happened?

Two utility bugs in @logicflow/core affect default text sizing and grid snapping:

  1. getBytesLength checks the whole string instead of the current character. In packages/core/src/util/edge.ts#L809, the loop reads const c = word.charCodeAt(i) but tests if (word.match(/[A-Z]/)), so a single capital letter gives every character in word weight 1.5. getSvgTextSize (edge label background <rect> in LineText) and getSvgTextWidthHeight (TextNodeModel.width) both call it:

    • Lowercase ASCII characters (weight 1) count as 1.5, making 'Approve' 50% wider than 'approve' (75 vs 51 at fontSize: 12).
    • CJK characters (weight 2) also drop to 1.5, so prepending 'A' to '网关审批流程节点' shrinks the computed width from 99 to 87 and the text overflows its box.
  2. snapToGrid skips 0. In packages/core/src/util/geometry.ts#L9, gridSize * Math.round(point / gridSize) || point falls back to point whenever the snapped coordinate is 0 (|point| < gridSize / 2). When snapGrid: true, nodes dragged, dropped, or added near x = 0 or y = 0 keep their raw coordinate instead of snapping to 0 (and getModelAfterSnapToGrid in GraphModel.ts also guards with if (nodeX && nodeY), skipping both axes when either coordinate is 0).

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:

  • snapToGrid snaps 4 and -4 to 0 ([ 0, 0, 10, 10 ]).
  • getBytesLength tests character i (c >= 0x41 && c <= 0x5a), giving 7.5 for "Approve" (width 51) and 17.5 for "A网关审批流程节点" (width 111).
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/

Lingua principale
TypeScript
Stelle
11.8k
Fork
1.4k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di didi/LogicFlow

Tutte le issue di didi/LogicFlow

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.