feat(editor): various text related improvements (#10979)

This commit is contained in:
David Luzar
2026-03-19 16:00:58 +01:00
committed by GitHub
parent e8b4620a96
commit 81ab857a6f
13 changed files with 518 additions and 104 deletions
@@ -224,7 +224,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 29,
"version": 28,
"width": "94.00000",
"x": 0,
"y": 0,
@@ -350,7 +350,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
],
"mode": "orbit",
},
"version": 28,
"version": 27,
"width": "88.00000",
},
"inserted": {
@@ -381,7 +381,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
],
"mode": "orbit",
},
"version": 25,
"version": 24,
"width": "88.00000",
},
},
@@ -437,7 +437,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
],
],
"startBinding": null,
"version": 29,
"version": 28,
"width": "94.00000",
"x": 0,
"y": 0,
@@ -462,7 +462,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
],
"mode": "orbit",
},
"version": 28,
"version": 27,
"width": "88.00000",
"x": 6,
"y": "7.20923",
@@ -1360,9 +1360,9 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 8,
"version": 7,
"width": 88,
"x": 6,
"x": "6.00000",
"y": "2.00947",
}
`;
@@ -1537,12 +1537,12 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
],
"mode": "orbit",
},
"version": 8,
"version": 7,
},
"inserted": {
"endBinding": null,
"startBinding": null,
"version": 7,
"version": 6,
},
},
},
@@ -1722,7 +1722,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"updated": 1,
"version": 8,
"width": 88,
"x": 6,
"x": "6.00000",
"y": "38.80379",
}
`;
@@ -1867,7 +1867,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"type": "arrow",
"version": 8,
"width": 88,
"x": 6,
"x": "6.00000",
"y": "38.80379",
},
"inserted": {
@@ -2416,7 +2416,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 12,
"version": 11,
"width": 488,
"x": 6,
"y": "-5.39000",
@@ -2581,7 +2581,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "arrow",
"version": 12,
"version": 11,
"width": 488,
"x": 6,
"y": "-5.39000",
@@ -16254,7 +16254,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 10,
"version": 11,
"width": "88.00000",
"x": 6,
"y": "0.01000",
@@ -16307,7 +16307,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
],
"mode": "orbit",
},
"version": 10,
"version": 11,
},
"inserted": {
"endBinding": {
@@ -16327,7 +16327,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
],
"mode": "orbit",
},
"version": 8,
"version": 9,
},
},
},
@@ -16669,14 +16669,14 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "arrow",
"version": 7,
"version": 8,
"width": "88.00000",
"x": 6,
"y": "0.00880",
},
"inserted": {
"isDeleted": true,
"version": 6,
"version": 7,
},
},
},
@@ -17002,7 +17002,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 10,
"version": 11,
"width": "88.00000",
"x": 6,
"y": "0.01000",
@@ -17307,14 +17307,14 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "arrow",
"version": 10,
"version": 11,
"width": "88.00000",
"x": 6,
"y": "0.01000",
},
"inserted": {
"isDeleted": true,
"version": 8,
"version": 9,
},
},
},
@@ -17648,7 +17648,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 10,
"version": 11,
"width": "88.00000",
"x": 6,
"y": "0.01000",
@@ -17953,14 +17953,14 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "arrow",
"version": 10,
"version": 11,
"width": "88.00000",
"x": 6,
"y": "0.01000",
},
"inserted": {
"isDeleted": true,
"version": 8,
"version": 9,
},
},
},
@@ -18292,7 +18292,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 10,
"version": 11,
"width": "88.00000",
"x": 6,
"y": "0.01000",
@@ -18361,7 +18361,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
],
"mode": "orbit",
},
"version": 10,
"version": 11,
},
"inserted": {
"endBinding": {
@@ -18373,7 +18373,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"mode": "orbit",
},
"startBinding": null,
"version": 8,
"version": 9,
},
},
"id2": {
@@ -18683,14 +18683,14 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "arrow",
"version": 7,
"version": 8,
"width": "88.00000",
"x": 6,
"y": "0.00880",
},
"inserted": {
"isDeleted": true,
"version": 6,
"version": 7,
},
},
},
@@ -19044,7 +19044,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeWidth": 2,
"type": "arrow",
"updated": 1,
"version": 11,
"version": 12,
"width": "88.00000",
"x": 6,
"y": "0.01000",
@@ -19124,12 +19124,12 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
],
"mode": "orbit",
},
"version": 11,
"version": 12,
},
"inserted": {
"endBinding": null,
"startBinding": null,
"version": 9,
"version": 10,
},
},
},
@@ -19431,14 +19431,14 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "arrow",
"version": 7,
"version": 8,
"width": "88.00000",
"x": 6,
"y": "0.00880",
},
"inserted": {
"isDeleted": true,
"version": 6,
"version": 7,
},
},
},
+12 -2
View File
@@ -4,6 +4,7 @@ import {
elementCenterPoint,
getCommonBounds,
getElementPointsCoords,
getLineHeightInPx,
} from "@excalidraw/element";
import { cropElement } from "@excalidraw/element";
import {
@@ -20,7 +21,7 @@ import {
isTextElement,
isFrameLikeElement,
} from "@excalidraw/element";
import { KEYS, arrayToMap } from "@excalidraw/common";
import { KEYS, arrayToMap, getLineHeight } from "@excalidraw/common";
import type { GlobalPoint, LocalPoint, Radians } from "@excalidraw/math";
@@ -516,8 +517,17 @@ export class UI {
UI.clickTool(type);
if (type === "text") {
const clickY = h.state.gridModeEnabled
? y
: y +
getLineHeightInPx(
h.state.currentItemFontSize,
getLineHeight(h.state.currentItemFontFamily),
) /
2;
mouse.reset();
mouse.click(x, y);
mouse.click(x, clickY);
} else if ((type === "line" || type === "arrow") && points.length > 2) {
points.forEach((point) => {
mouse.reset();