prevent editing text inside of a component that is not text editable

This commit is contained in:
Oleg Isonen committed 2022-07-05 20:24:08 +02:00
1 parent d078ab2b91
commit 2cddf59606
2 files changed
+9 -1

No files matched your search

+3
View File
@@ -8,6 +8,7 @@ import {
useRootInstance,
useTextEditingInstanceId,
} from "~/shared/nano-states";
import { primitives } from "~/shared/canvas-components";
const inputTags = ["INPUT", "SELECT", "TEXTAREA"] as const;
@@ -99,6 +100,8 @@ export const useShortcuts = () => {
"enter",
(event) => {
if (selectedInstance === undefined) return;
const { isContentEditable } = primitives[selectedInstance.component];
if (isContentEditable === false) return;
// Prevents inserting a newline when entering text-editing mode
event.preventDefault();
setEditingInstanceId(selectedInstance.id);
@@ -86,7 +86,12 @@ export const useTrackSelectedElement = () => {
if (component === undefined || component in primitives === false) {
return;
}
const { isInlineOnly } = primitives[component];
const { isInlineOnly, isContentEditable } = primitives[component];
if (isContentEditable === false) {
return;
}
// When user double clicks on an inline instance, we need to select the parent instance and put it indo text editing mode.
// Inline instances are not directly, only through parent instance.
if (isInlineOnly) {