feat: support decreasing/increasing fontSize via keyboard (#4553)

Co-authored-by: david <dw@dw.local>
This commit is contained in:
David Luzar 2022-01-12 15:21:36 +01:00 committed by GitHub
parent 4501d6d630
commit a51ed9ced6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 214 additions and 93 deletions

View file

@ -8,16 +8,13 @@ import {
import Scene from "../scene/Scene";
import { isBoundToContainer, isTextElement } from "./typeChecks";
import { CLASSES, BOUND_TEXT_PADDING } from "../constants";
import {
ExcalidrawBindableElement,
ExcalidrawElement,
ExcalidrawTextElement,
} from "./types";
import { ExcalidrawElement, ExcalidrawTextElement } from "./types";
import { AppState } from "../types";
import { mutateElement } from "./mutateElement";
import {
getApproxLineHeight,
getBoundTextElementId,
getContainerElement,
wrapText,
} from "./textElement";
@ -102,9 +99,7 @@ export const textWysiwyg = ({
if (updatedElement && isTextElement(updatedElement)) {
let coordX = updatedElement.x;
let coordY = updatedElement.y;
const container = updatedElement?.containerId
? Scene.getScene(updatedElement)!.getElement(updatedElement.containerId)
: null;
const container = getContainerElement(updatedElement);
let maxWidth = updatedElement.width;
let maxHeight = updatedElement.height;
@ -274,9 +269,7 @@ export const textWysiwyg = ({
let height = "auto";
if (lines === 2) {
const container = Scene.getScene(element)!.getElement(
element.containerId,
);
const container = getContainerElement(element);
const actualLineCount = wrapText(
editable.value,
getFontString(element),
@ -300,13 +293,16 @@ export const textWysiwyg = ({
}
editable.onkeydown = (event) => {
event.stopPropagation();
if (!event[KEYS.CTRL_OR_CMD]) {
event.stopPropagation();
}
if (event.key === KEYS.ESCAPE) {
event.preventDefault();
submittedViaKeyboard = true;
handleSubmit();
} else if (event.key === KEYS.ENTER && event[KEYS.CTRL_OR_CMD]) {
event.preventDefault();
event.stopPropagation();
if (event.isComposing || event.keyCode === 229) {
return;
}
@ -319,6 +315,7 @@ export const textWysiwyg = ({
event.code === CODES.BRACKET_RIGHT))
) {
event.preventDefault();
event.stopPropagation();
if (event.shiftKey || event.code === CODES.BRACKET_LEFT) {
outdent();
} else {
@ -443,9 +440,7 @@ export const textWysiwyg = ({
}
let wrappedText = "";
if (isTextElement(updateElement) && updateElement?.containerId) {
const container = Scene.getScene(updateElement)!.getElement(
updateElement.containerId,
) as ExcalidrawBindableElement;
const container = getContainerElement(updateElement);
if (container) {
wrappedText = wrapText(