mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: horizontal text alignment for bound text when resizing (#5721)
* Update textElement.ts * Add test * don't use modifier keys when not needed Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
This commit is contained in:
parent
4cb6f09559
commit
b477c2ad6b
4 changed files with 113 additions and 41 deletions
|
@ -3,18 +3,13 @@ import { render } from "./test-utils";
|
|||
import App from "../components/App";
|
||||
import * as Renderer from "../renderer/renderScene";
|
||||
import { reseed } from "../random";
|
||||
import { UI, Pointer, Keyboard, KeyboardModifiers } from "./helpers/ui";
|
||||
import {
|
||||
getTransformHandles,
|
||||
TransformHandleDirection,
|
||||
} from "../element/transformHandles";
|
||||
import { ExcalidrawElement, ExcalidrawTextElement } from "../element/types";
|
||||
import { UI, Keyboard } from "./helpers/ui";
|
||||
import { resize } from "./utils";
|
||||
import { ExcalidrawTextElement } from "../element/types";
|
||||
import ExcalidrawApp from "../excalidraw-app";
|
||||
import { API } from "./helpers/api";
|
||||
import { KEYS } from "../keys";
|
||||
|
||||
const mouse = new Pointer("mouse");
|
||||
|
||||
// Unmount ReactDOM from root
|
||||
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
||||
|
||||
|
@ -127,26 +122,6 @@ describe("resize rectangle ellipses and diamond elements", () => {
|
|||
);
|
||||
});
|
||||
|
||||
const resize = (
|
||||
element: ExcalidrawElement,
|
||||
handleDir: TransformHandleDirection,
|
||||
mouseMove: [number, number],
|
||||
keyboardModifiers: KeyboardModifiers = {},
|
||||
) => {
|
||||
mouse.select(element);
|
||||
const handle = getTransformHandles(element, h.state.zoom, "mouse")[
|
||||
handleDir
|
||||
]!;
|
||||
const clientX = handle[0] + handle[2] / 2;
|
||||
const clientY = handle[1] + handle[3] / 2;
|
||||
Keyboard.withModifierKeys(keyboardModifiers, () => {
|
||||
mouse.reset();
|
||||
mouse.down(clientX, clientY);
|
||||
mouse.move(mouseMove[0], mouseMove[1]);
|
||||
mouse.up();
|
||||
});
|
||||
};
|
||||
|
||||
describe("Test text element", () => {
|
||||
it("should update font size via keyboard", async () => {
|
||||
await render(<ExcalidrawApp />);
|
||||
|
|
29
src/tests/utils.ts
Normal file
29
src/tests/utils.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import {
|
||||
getTransformHandles,
|
||||
TransformHandleDirection,
|
||||
} from "../element/transformHandles";
|
||||
import { ExcalidrawElement } from "../element/types";
|
||||
import { Keyboard, KeyboardModifiers, Pointer } from "./helpers/ui";
|
||||
|
||||
const mouse = new Pointer("mouse");
|
||||
const { h } = window;
|
||||
|
||||
export const resize = (
|
||||
element: ExcalidrawElement,
|
||||
handleDir: TransformHandleDirection,
|
||||
mouseMove: [number, number],
|
||||
keyboardModifiers: KeyboardModifiers = {},
|
||||
) => {
|
||||
mouse.select(element);
|
||||
const handle = getTransformHandles(element, h.state.zoom, "mouse")[
|
||||
handleDir
|
||||
]!;
|
||||
const clientX = handle[0] + handle[2] / 2;
|
||||
const clientY = handle[1] + handle[3] / 2;
|
||||
Keyboard.withModifierKeys(keyboardModifiers, () => {
|
||||
mouse.reset();
|
||||
mouse.down(clientX, clientY);
|
||||
mouse.move(mouseMove[0], mouseMove[1]);
|
||||
mouse.up();
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue