fix: keyboard-zooming in wysiwyg should zoom canvas (#4676)
This commit is contained in:
parent
dcee594b66
commit
4b5270ab12
@ -1931,7 +1931,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
textWysiwyg({
|
textWysiwyg({
|
||||||
id: element.id,
|
id: element.id,
|
||||||
appState: this.state,
|
|
||||||
canvas: this.canvas,
|
canvas: this.canvas,
|
||||||
getViewportCoords: (x, y) => {
|
getViewportCoords: (x, y) => {
|
||||||
const { x: viewportX, y: viewportY } = sceneCoordsToViewportCoords(
|
const { x: viewportX, y: viewportY } = sceneCoordsToViewportCoords(
|
||||||
|
@ -2,7 +2,7 @@ import ReactDOM from "react-dom";
|
|||||||
import ExcalidrawApp from "../excalidraw-app";
|
import ExcalidrawApp from "../excalidraw-app";
|
||||||
import { render, screen } from "../tests/test-utils";
|
import { render, screen } from "../tests/test-utils";
|
||||||
import { Keyboard, Pointer, UI } from "../tests/helpers/ui";
|
import { Keyboard, Pointer, UI } from "../tests/helpers/ui";
|
||||||
import { KEYS } from "../keys";
|
import { CODES, KEYS } from "../keys";
|
||||||
import { fireEvent } from "../tests/test-utils";
|
import { fireEvent } from "../tests/test-utils";
|
||||||
import { BOUND_TEXT_PADDING, FONT_FAMILY } from "../constants";
|
import { BOUND_TEXT_PADDING, FONT_FAMILY } from "../constants";
|
||||||
import {
|
import {
|
||||||
@ -18,6 +18,8 @@ const mouse = new Pointer("mouse");
|
|||||||
|
|
||||||
describe("textWysiwyg", () => {
|
describe("textWysiwyg", () => {
|
||||||
describe("Test unbounded text", () => {
|
describe("Test unbounded text", () => {
|
||||||
|
const { h } = window;
|
||||||
|
|
||||||
let textarea: HTMLTextAreaElement;
|
let textarea: HTMLTextAreaElement;
|
||||||
let textElement: ExcalidrawTextElement;
|
let textElement: ExcalidrawTextElement;
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -197,6 +199,38 @@ describe("textWysiwyg", () => {
|
|||||||
);
|
);
|
||||||
expect(textElement.fontSize).toBe(origFontSize);
|
expect(textElement.fontSize).toBe(origFontSize);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("zooming via keyboard should zoom canvas", () => {
|
||||||
|
expect(h.state.zoom.value).toBe(1);
|
||||||
|
textarea.dispatchEvent(
|
||||||
|
new KeyboardEvent("keydown", {
|
||||||
|
code: CODES.MINUS,
|
||||||
|
ctrlKey: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(h.state.zoom.value).toBe(0.9);
|
||||||
|
textarea.dispatchEvent(
|
||||||
|
new KeyboardEvent("keydown", {
|
||||||
|
code: CODES.NUM_SUBTRACT,
|
||||||
|
ctrlKey: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(h.state.zoom.value).toBe(0.8);
|
||||||
|
textarea.dispatchEvent(
|
||||||
|
new KeyboardEvent("keydown", {
|
||||||
|
code: CODES.NUM_ADD,
|
||||||
|
ctrlKey: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(h.state.zoom.value).toBe(0.9);
|
||||||
|
textarea.dispatchEvent(
|
||||||
|
new KeyboardEvent("keydown", {
|
||||||
|
code: CODES.EQUAL,
|
||||||
|
ctrlKey: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(h.state.zoom.value).toBe(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Test bounded text", () => {
|
describe("Test bounded text", () => {
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
actionDecreaseFontSize,
|
actionDecreaseFontSize,
|
||||||
actionIncreaseFontSize,
|
actionIncreaseFontSize,
|
||||||
} from "../actions/actionProperties";
|
} from "../actions/actionProperties";
|
||||||
|
import { actionZoomIn, actionZoomOut } from "../actions/actionCanvas";
|
||||||
import App from "../components/App";
|
import App from "../components/App";
|
||||||
|
|
||||||
const normalizeText = (text: string) => {
|
const normalizeText = (text: string) => {
|
||||||
@ -60,7 +61,6 @@ const getTransform = (
|
|||||||
|
|
||||||
export const textWysiwyg = ({
|
export const textWysiwyg = ({
|
||||||
id,
|
id,
|
||||||
appState,
|
|
||||||
onChange,
|
onChange,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
getViewportCoords,
|
getViewportCoords,
|
||||||
@ -70,7 +70,6 @@ export const textWysiwyg = ({
|
|||||||
app,
|
app,
|
||||||
}: {
|
}: {
|
||||||
id: ExcalidrawElement["id"];
|
id: ExcalidrawElement["id"];
|
||||||
appState: AppState;
|
|
||||||
onChange?: (text: string) => void;
|
onChange?: (text: string) => void;
|
||||||
onSubmit: (data: {
|
onSubmit: (data: {
|
||||||
text: string;
|
text: string;
|
||||||
@ -102,6 +101,7 @@ export const textWysiwyg = ({
|
|||||||
let originalContainerHeight: number;
|
let originalContainerHeight: number;
|
||||||
|
|
||||||
const updateWysiwygStyle = () => {
|
const updateWysiwygStyle = () => {
|
||||||
|
const appState = app.state;
|
||||||
const updatedElement = Scene.getScene(element)?.getElement(
|
const updatedElement = Scene.getScene(element)?.getElement(
|
||||||
id,
|
id,
|
||||||
) as ExcalidrawTextElement;
|
) as ExcalidrawTextElement;
|
||||||
@ -291,7 +291,15 @@ export const textWysiwyg = ({
|
|||||||
editable.onkeydown = (event) => {
|
editable.onkeydown = (event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
if (actionDecreaseFontSize.keyTest(event)) {
|
if (actionZoomIn.keyTest(event)) {
|
||||||
|
event.preventDefault();
|
||||||
|
app.actionManager.executeAction(actionZoomIn);
|
||||||
|
updateWysiwygStyle();
|
||||||
|
} else if (actionZoomOut.keyTest(event)) {
|
||||||
|
event.preventDefault();
|
||||||
|
app.actionManager.executeAction(actionZoomOut);
|
||||||
|
updateWysiwygStyle();
|
||||||
|
} else if (actionDecreaseFontSize.keyTest(event)) {
|
||||||
app.actionManager.executeAction(actionDecreaseFontSize);
|
app.actionManager.executeAction(actionDecreaseFontSize);
|
||||||
} else if (actionIncreaseFontSize.keyTest(event)) {
|
} else if (actionIncreaseFontSize.keyTest(event)) {
|
||||||
app.actionManager.executeAction(actionIncreaseFontSize);
|
app.actionManager.executeAction(actionIncreaseFontSize);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user