Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
istarkov committed Oct 25, 2024
1 parent a998902 commit c93ec65
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions apps/builder/app/canvas/features/text-editor/text-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
import { nanoid } from "nanoid";
import { createRegularStyleSheet } from "@webstudio-is/css-engine";
import type { Instance, Instances } from "@webstudio-is/sdk";
import { idAttribute } from "@webstudio-is/react-sdk";
import { collapsedAttribute, idAttribute } from "@webstudio-is/react-sdk";
import type { InstanceSelector } from "~/shared/tree-utils";
import { ToolbarConnectorPlugin } from "./toolbar-connector";
import { type Refs, $convertToLexical, $convertToUpdates } from "./interop";
Expand All @@ -57,7 +57,10 @@ import {
$selectedPage,
$textEditingInstanceSelector,
} from "~/shared/nano-states";
import { getVisibleElementsByInstanceSelector } from "~/shared/dom-utils";
import {
getElementByInstanceSelector,
getVisibleElementsByInstanceSelector,
} from "~/shared/dom-utils";
import deepEqual from "fast-deep-equal";

const BindInstanceToNodePlugin = ({ refs }: { refs: Refs }) => {
Expand Down Expand Up @@ -892,6 +895,20 @@ export const TextEditor = ({
const nextSelector = results[nextIndex];

if (getVisibleElementsByInstanceSelector(nextSelector).length > 0) {
const instance = instances.get(nextSelector[0]);

// opnionated: Elements without children can be spacers, so skip them if not collapsed.
if (instance?.children.length === 0) {
const elt = getElementByInstanceSelector(nextSelector);
if (elt === undefined) {
continue;
}

if (!elt.hasAttribute(collapsedAttribute)) {
continue;
}
}

handleChange(state);

$textEditingInstanceSelector.set({
Expand Down

0 comments on commit c93ec65

Please sign in to comment.