Repository: excalidraw/excalidraw
File: src/element/textWysiwyg.tsx (TypeScript)

Code before:
      .reverse();
  };

  const stopEvent = (event: Event) => {
    event.preventDefault();
    event.stopPropagation();
  };

  // using a state variable instead of passing it to the handleSubmit callback
  // so that we don't need to create separate a callback for event handlers
  let submittedViaKeyboard = false;
  const handleSubmit = () => {
    // cleanup must be run before onSubmit otherwise when app blurs the wysiwyg
    // it'd get stuck in an infinite loop of blur→onSubmit after we re-focus the
    // wysiwyg on update
    cleanup();
    const updateElement = Scene.getScene(element)?.getElement(
      element.id,
    ) as ExcalidrawTextElement;
    if (!updateElement) {
      return;
    }
    let text = editable.value;
    const container = getContainerElement(updateElement);

    if (container) {
      text = updateElement.text;
      const editorHeight = Number(editable.style.height.slice(0, -2));
      if (editable.value) {
        // Don't mutate if text is not updated, this happens when text
        // properties updated since vertically align is taken care in
        // redrawTextBoundingBox already
        if (initialText !== editable.value) {
          mutateElement(updateElement, {
            // vertically center align
            y: container.y + container.height / 2 - editorHeight / 2,
            height: editorHeight,
            width: Number(editable.style.width.slice(0, -2)),
            // preserve padding
            x: container.x + BOUND_TEXT_PADDING,
            angle: container.angle,
          });
        }

        const boundTextElementId = getBoundTextElementId(container);
        if (!boundTextElementId || boundTextElementId !== element.id) {
          mutateElement(container, {
            boundElements: (container.boundElements || []).concat({
              type: "text",
              id: element.id,
            }),

Review comment (bug):
This is just for spec, for some reason in specs If `change` event is triggered, its failing when `updatingBoundElements` in one of the specs, tried debugging it but no luck yet so keeping it `editable.value` as before for unbounded text

Code after:
          ),
        [] as number[],
      )
      .reverse();
  };

  const stopEvent = (event: Event) => {
    event.preventDefault();
    event.stopPropagation();
  };

  // using a state variable instead of passing it to the handleSubmit callback
  // so that we don't need to create separate a callback for event handlers
  let submittedViaKeyboard = false;
  const handleSubmit = () => {
    // cleanup must be run before onSubmit otherwise when app blurs the wysiwyg
    // it'd get stuck in an infinite loop of blur→onSubmit after we re-focus the
    // wysiwyg on update
    cleanup();
    const updateElement = Scene.getScene(element)?.getElement(
      element.id,
    ) as ExcalidrawTextElement;
    if (!updateElement) {
      return;
    }
    let text = editable.value;
    const container = getContainerElement(updateElement);

    if (container) {
      text = updateElement.text;
      if (editable.value) {
        const boundTextElementId = getBoundTextElementId(container);
        if (!boundTextElementId || boundTextElementId !== element.id) {
          mutateElement(container, {
            boundElements: (container.boundElements || []).concat({
              type: "text",
              id: element.id,
            }),
          });
        }
      } else {
        mutateElement(container, {
          boundElements: container.boundElements?.filter(
            (ele) =>
              !isTextElement(
                ele as ExcalidrawTextElement | ExcalidrawLinearElement,
              ),
          ),
        });
      }
    }