fix(editor): prevent duplicate lasso toolbar item (#11286)
This commit is contained in:
@@ -119,15 +119,12 @@ export const SHAPES = [
|
|||||||
export const getToolbarTools = (app: AppClassProperties) => {
|
export const getToolbarTools = (app: AppClassProperties) => {
|
||||||
return app.state.preferredSelectionTool.type === "lasso"
|
return app.state.preferredSelectionTool.type === "lasso"
|
||||||
? ([
|
? ([
|
||||||
|
SHAPES[0],
|
||||||
{
|
{
|
||||||
|
...SHAPES[1],
|
||||||
value: "lasso",
|
value: "lasso",
|
||||||
icon: SelectionIcon,
|
|
||||||
key: KEYS.V,
|
|
||||||
numericKey: KEYS["1"],
|
|
||||||
fillable: true,
|
|
||||||
toolbar: true,
|
|
||||||
},
|
},
|
||||||
...SHAPES.slice(1),
|
...SHAPES.slice(2),
|
||||||
] as const)
|
] as const)
|
||||||
: SHAPES;
|
: SHAPES;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import { resolvablePromise } from "@excalidraw/common";
|
|||||||
|
|
||||||
import { Excalidraw } from "../index";
|
import { Excalidraw } from "../index";
|
||||||
|
|
||||||
|
import { getToolbarTools } from "../components/shapes";
|
||||||
|
|
||||||
import { Pointer } from "./helpers/ui";
|
import { Pointer } from "./helpers/ui";
|
||||||
import { act, render } from "./test-utils";
|
import { act, render } from "./test-utils";
|
||||||
|
|
||||||
import type { ExcalidrawImperativeAPI } from "../types";
|
import type { AppClassProperties, ExcalidrawImperativeAPI } from "../types";
|
||||||
|
|
||||||
describe("setActiveTool()", () => {
|
describe("setActiveTool()", () => {
|
||||||
const h = window.h;
|
const h = window.h;
|
||||||
@@ -66,3 +68,27 @@ describe("setActiveTool()", () => {
|
|||||||
expect(h.state.activeTool.customType).toBe("comment");
|
expect(h.state.activeTool.customType).toBe("comment");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("getToolbarTools()", () => {
|
||||||
|
const getToolValues = (preferredSelectionTool: "selection" | "lasso") =>
|
||||||
|
getToolbarTools({
|
||||||
|
state: {
|
||||||
|
preferredSelectionTool: {
|
||||||
|
type: preferredSelectionTool,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as AppClassProperties).map((tool) => tool.value);
|
||||||
|
|
||||||
|
it("does not include lasso when selection is preferred", () => {
|
||||||
|
const toolValues = getToolValues("selection");
|
||||||
|
|
||||||
|
expect(toolValues.filter((value) => value === "selection")).toHaveLength(1);
|
||||||
|
expect(toolValues.filter((value) => value === "lasso")).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("replaces selection with lasso when lasso is preferred", () => {
|
||||||
|
const toolValues = getToolValues("lasso");
|
||||||
|
|
||||||
|
expect(toolValues.filter((value) => value === "lasso")).toHaveLength(1);
|
||||||
|
expect(toolValues.filter((value) => value === "selection")).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user