Compare commits

..

4 Commits

Author SHA1 Message Date
dwelle
44660ce313 debug 2021-08-23 23:00:06 +02:00
dwelle
ac00b4ef2b prevent dragging the editing text element 2021-05-28 21:16:27 +02:00
dwelle
bf7810306c disable touble-tap-to-create-text on mobile 2021-05-28 21:15:43 +02:00
dwelle
9d0b7b0f2c stop disabling ts for handleCanvasDoubleClick 2021-05-28 21:14:52 +02:00
3 changed files with 25 additions and 20 deletions

View File

@@ -322,8 +322,6 @@ class App extends React.Component<AppProps, AppState> {
private id: string; private id: string;
private history: History; private history: History;
private activeWysiwyg: null | { handleSubmit: () => void } = null;
constructor(props: AppProps) { constructor(props: AppProps) {
super(props); super(props);
const defaultAppState = getDefaultAppState(); const defaultAppState = getDefaultAppState();
@@ -1206,11 +1204,16 @@ class App extends React.Component<AppProps, AppState> {
// event.touches.length === 1 will also prevent inserting text when user's zooming // event.touches.length === 1 will also prevent inserting text when user's zooming
if (didTapTwice && event.touches.length === 1) { if (didTapTwice && event.touches.length === 1) {
const [touch] = event.touches; const [touch] = event.touches;
// @ts-ignore this.handleCanvasDoubleClick(
this.handleCanvasDoubleClick({ {
clientX: touch.clientX, clientX: touch.clientX,
clientY: touch.clientY, clientY: touch.clientY,
}); ctrlKey: false,
metaKey: false,
altKey: false,
},
false,
);
didTapTwice = false; didTapTwice = false;
clearTimeout(tappedTwiceTimer); clearTimeout(tappedTwiceTimer);
} }
@@ -1765,7 +1768,7 @@ class App extends React.Component<AppProps, AppState> {
]); ]);
}; };
const { handleSubmit } = textWysiwyg({ textWysiwyg({
id: element.id, id: element.id,
appState: this.state, appState: this.state,
canvas: this.canvas, canvas: this.canvas,
@@ -1789,7 +1792,6 @@ class App extends React.Component<AppProps, AppState> {
} }
}), }),
onSubmit: withBatchedUpdates(({ text, viaKeyboard }) => { onSubmit: withBatchedUpdates(({ text, viaKeyboard }) => {
this.activeWysiwyg = null;
const isDeleted = !text.trim(); const isDeleted = !text.trim();
updateElement(text, isDeleted); updateElement(text, isDeleted);
// select the created text element only if submitting via keyboard // select the created text element only if submitting via keyboard
@@ -1831,8 +1833,6 @@ class App extends React.Component<AppProps, AppState> {
// do an initial update to re-initialize element position since we were // do an initial update to re-initialize element position since we were
// modifying element's x/y for sake of editor (case: syncing to remote) // modifying element's x/y for sake of editor (case: syncing to remote)
updateElement(element.text); updateElement(element.text);
this.activeWysiwyg = { handleSubmit };
} }
private getTextElementAtPosition( private getTextElementAtPosition(
@@ -1885,6 +1885,7 @@ class App extends React.Component<AppProps, AppState> {
sceneX, sceneX,
sceneY, sceneY,
insertAtParentCenter = true, insertAtParentCenter = true,
createTextIfNotExists = true,
}: { }: {
/** X position to insert text at */ /** X position to insert text at */
sceneX: number; sceneX: number;
@@ -1892,9 +1893,14 @@ class App extends React.Component<AppProps, AppState> {
sceneY: number; sceneY: number;
/** whether to attempt to insert at element center if applicable */ /** whether to attempt to insert at element center if applicable */
insertAtParentCenter?: boolean; insertAtParentCenter?: boolean;
createTextIfNotExists?: boolean;
}) => { }) => {
const existingTextElement = this.getTextElementAtPosition(sceneX, sceneY); const existingTextElement = this.getTextElementAtPosition(sceneX, sceneY);
// if (!existingTextElement && !createTextIfNotExists) {
// return;
// }
const parentCenterPosition = const parentCenterPosition =
insertAtParentCenter && insertAtParentCenter &&
this.getTextWysiwygSnappedToCenterPosition( this.getTextWysiwygSnappedToCenterPosition(
@@ -1966,7 +1972,11 @@ class App extends React.Component<AppProps, AppState> {
}; };
private handleCanvasDoubleClick = ( private handleCanvasDoubleClick = (
event: React.MouseEvent<HTMLCanvasElement>, event: Pick<
React.PointerEvent<HTMLCanvasElement>,
"clientX" | "clientY" | "ctrlKey" | "metaKey" | "altKey"
>,
createTextIfNotExists = true,
) => { ) => {
// case: double-clicking with arrow/line tool selected would both create // case: double-clicking with arrow/line tool selected would both create
// text and enter multiElement mode // text and enter multiElement mode
@@ -2037,6 +2047,7 @@ class App extends React.Component<AppProps, AppState> {
sceneX, sceneX,
sceneY, sceneY,
insertAtParentCenter: !event.altKey, insertAtParentCenter: !event.altKey,
createTextIfNotExists,
}); });
} }
}; };
@@ -2290,10 +2301,6 @@ class App extends React.Component<AppProps, AppState> {
) => { ) => {
event.persist(); event.persist();
if (this.activeWysiwyg) {
this.activeWysiwyg.handleSubmit();
}
// remove any active selection when we start to interact with canvas // remove any active selection when we start to interact with canvas
// (mainly, we care about removing selection outside the component which // (mainly, we care about removing selection outside the component which
// would prevent our copy handling otherwise) // would prevent our copy handling otherwise)
@@ -3199,7 +3206,7 @@ class App extends React.Component<AppProps, AppState> {
const selectedElements = getSelectedElements( const selectedElements = getSelectedElements(
this.scene.getElements(), this.scene.getElements(),
this.state, this.state,
); ).filter((element) => element.id !== this.state.editingElement?.id);
// prevent dragging even if we're no longer holding cmd/ctrl otherwise // prevent dragging even if we're no longer holding cmd/ctrl otherwise
// it would have weird results (stuff jumping all over the screen) // it would have weird results (stuff jumping all over the screen)
if (selectedElements.length > 0 && !pointerDownState.withCmdOrCtrl) { if (selectedElements.length > 0 && !pointerDownState.withCmdOrCtrl) {

View File

@@ -16,7 +16,7 @@ describe("textWysiwyg", () => {
const element = UI.createElement("text"); const element = UI.createElement("text");
new Pointer("mouse").doubleClickOn(element); new Pointer("mouse").clickOn(element);
textarea = document.querySelector( textarea = document.querySelector(
".excalidraw-textEditorContainer > textarea", ".excalidraw-textEditorContainer > textarea",
)!; )!;

View File

@@ -368,6 +368,4 @@ export const textWysiwyg = ({
excalidrawContainer excalidrawContainer
?.querySelector(".excalidraw-textEditorContainer")! ?.querySelector(".excalidraw-textEditorContainer")!
.appendChild(editable); .appendChild(editable);
return { handleSubmit };
}; };