fix: binding text to non-bindable containers and not always preferring selection (#4655)

This commit is contained in:
David Luzar 2022-03-02 17:04:09 +01:00 committed by GitHub
parent 8e26d5b500
commit 6d0716eb6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 336 additions and 85 deletions

View file

@ -152,6 +152,7 @@ describe("element binding", () => {
UI.clickTool("text");
mouse.clickAt(text.x + 50, text.y + 50);
const editor = document.querySelector(
".excalidraw-textEditorContainer > textarea",
) as HTMLTextAreaElement;

View file

@ -9,7 +9,7 @@ Object {
"endBinding": null,
"fillStyle": "hachure",
"groupIds": Array [],
"height": 0,
"height": 100,
"id": "id-arrow01",
"isDeleted": false,
"lastCommittedPoint": null,
@ -21,8 +21,8 @@ Object {
0,
],
Array [
0,
0,
100,
100,
],
],
"roughness": 1,
@ -37,7 +37,7 @@ Object {
"updated": 1,
"version": 1,
"versionNonce": 0,
"width": 0,
"width": 100,
"x": 0,
"y": 0,
}
@ -180,7 +180,7 @@ Object {
"endBinding": null,
"fillStyle": "hachure",
"groupIds": Array [],
"height": 0,
"height": 100,
"id": "id-line01",
"isDeleted": false,
"lastCommittedPoint": null,
@ -192,8 +192,8 @@ Object {
0,
],
Array [
0,
0,
100,
100,
],
],
"roughness": 1,
@ -208,7 +208,7 @@ Object {
"updated": 1,
"version": 1,
"versionNonce": 0,
"width": 0,
"width": 100,
"x": 0,
"y": 0,
}
@ -223,7 +223,7 @@ Object {
"endBinding": null,
"fillStyle": "hachure",
"groupIds": Array [],
"height": 0,
"height": 100,
"id": "id-draw01",
"isDeleted": false,
"lastCommittedPoint": null,
@ -235,8 +235,8 @@ Object {
0,
],
Array [
0,
0,
100,
100,
],
],
"roughness": 1,
@ -251,7 +251,7 @@ Object {
"updated": 1,
"version": 1,
"versionNonce": 0,
"width": 0,
"width": 100,
"x": 0,
"y": 0,
}

View file

@ -14,6 +14,7 @@ import util from "util";
import path from "path";
import { getMimeType } from "../../data/blob";
import { newFreeDrawElement } from "../../element/newElement";
import { Point } from "../../types";
const readFile = util.promisify(fs.readFile);
@ -98,6 +99,7 @@ export class API {
containerId?: T extends "text"
? ExcalidrawTextElement["containerId"]
: never;
points?: T extends "arrow" | "line" ? readonly Point[] : never;
}): T extends "arrow" | "line"
? ExcalidrawLinearElement
: T extends "freedraw"
@ -158,10 +160,13 @@ export class API {
case "arrow":
case "line":
element = newLinearElement({
...base,
width,
height,
type: type as "arrow" | "line",
startArrowhead: null,
endArrowhead: null,
...base,
points: rest.points ?? [],
});
break;
}