fix: incorrectly selecting linear elements on creation while tool-locked (#5785)
This commit is contained in:
parent
2e5c798c71
commit
e8fba43cf6
@ -237,7 +237,7 @@ export const ShapesSwitcher = ({
|
|||||||
keyBindingLabel={`${numberKey}`}
|
keyBindingLabel={`${numberKey}`}
|
||||||
aria-label={capitalizeString(label)}
|
aria-label={capitalizeString(label)}
|
||||||
aria-keyshortcuts={shortcut}
|
aria-keyshortcuts={shortcut}
|
||||||
data-testid={value}
|
data-testid={`toolbar-${value}`}
|
||||||
onPointerDown={({ pointerType }) => {
|
onPointerDown={({ pointerType }) => {
|
||||||
if (!appState.penDetected && pointerType === "pen") {
|
if (!appState.penDetected && pointerType === "pen") {
|
||||||
setAppState({
|
setAppState({
|
||||||
|
@ -4836,10 +4836,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
} else {
|
} else {
|
||||||
this.setState((prevState) => ({
|
this.setState((prevState) => ({
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
selectedElementIds: {
|
|
||||||
...prevState.selectedElementIds,
|
|
||||||
[draggingElement.id]: true,
|
|
||||||
},
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ export const LockButton = (props: LockIconProps) => {
|
|||||||
onChange={props.onChange}
|
onChange={props.onChange}
|
||||||
checked={props.checked}
|
checked={props.checked}
|
||||||
aria-label={props.title}
|
aria-label={props.title}
|
||||||
|
data-testid="toolbar-lock"
|
||||||
/>
|
/>
|
||||||
<div className="ToolIcon__icon">
|
<div className="ToolIcon__icon">
|
||||||
{props.checked ? ICONS.CHECKED : ICONS.UNCHECKED}
|
{props.checked ? ICONS.CHECKED : ICONS.UNCHECKED}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { queries, buildQueries } from "@testing-library/react";
|
import { queries, buildQueries } from "@testing-library/react";
|
||||||
|
|
||||||
const toolMap = {
|
const toolMap = {
|
||||||
|
lock: "lock",
|
||||||
selection: "selection",
|
selection: "selection",
|
||||||
rectangle: "rectangle",
|
rectangle: "rectangle",
|
||||||
diamond: "diamond",
|
diamond: "diamond",
|
||||||
@ -15,7 +16,7 @@ export type ToolName = keyof typeof toolMap;
|
|||||||
|
|
||||||
const _getAllByToolName = (container: HTMLElement, tool: string) => {
|
const _getAllByToolName = (container: HTMLElement, tool: string) => {
|
||||||
const toolTitle = toolMap[tool as ToolName];
|
const toolTitle = toolMap[tool as ToolName];
|
||||||
return queries.getAllByTestId(container, toolTitle);
|
return queries.getAllByTestId(container, `toolbar-${toolTitle}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMultipleError = (_container: any, tool: any) =>
|
const getMultipleError = (_container: any, tool: any) =>
|
||||||
|
@ -11,7 +11,8 @@ import * as Renderer from "../renderer/renderScene";
|
|||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { reseed } from "../random";
|
import { reseed } from "../random";
|
||||||
import { API } from "./helpers/api";
|
import { API } from "./helpers/api";
|
||||||
import { Keyboard, Pointer } from "./helpers/ui";
|
import { Keyboard, Pointer, UI } from "./helpers/ui";
|
||||||
|
import { SHAPES } from "../shapes";
|
||||||
|
|
||||||
// Unmount ReactDOM from root
|
// Unmount ReactDOM from root
|
||||||
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
||||||
@ -380,3 +381,19 @@ describe("select single element on the scene", () => {
|
|||||||
h.elements.forEach((element) => expect(element).toMatchSnapshot());
|
h.elements.forEach((element) => expect(element).toMatchSnapshot());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("tool locking & selection", () => {
|
||||||
|
it("should not select newly created element while tool is locked", async () => {
|
||||||
|
await render(<ExcalidrawApp />);
|
||||||
|
|
||||||
|
UI.clickTool("lock");
|
||||||
|
expect(h.state.activeTool.locked).toBe(true);
|
||||||
|
|
||||||
|
for (const { value } of Object.values(SHAPES)) {
|
||||||
|
if (value !== "image" && value !== "selection") {
|
||||||
|
const element = UI.createElement(value);
|
||||||
|
expect(h.state.selectedElementIds[element.id]).not.toBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user