@lingjingai/script-editor 0.1.25 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -648,6 +648,7 @@ function EditableText({
648
648
  const [editing, setEditing] = useState(autoEdit);
649
649
  const [draft, setDraft] = useState(value);
650
650
  const caretRef = useRef(null);
651
+ const entryHeightRef = useRef(null);
651
652
  const inputRef = useRef(null);
652
653
  const committedRef = useRef(value);
653
654
  const editingSignal = useContext(EditingSignalContext);
@@ -699,7 +700,10 @@ function EditableText({
699
700
  if (!editing) return;
700
701
  const el = inputRef.current;
701
702
  if (!el) return;
702
- if (multiline) autoSize(el);
703
+ if (multiline) {
704
+ autoSize(el, entryHeightRef.current);
705
+ entryHeightRef.current = null;
706
+ }
703
707
  el.focus();
704
708
  const caret = caretRef.current;
705
709
  const pos = caret == null ? el.value.length : Math.min(caret, el.value.length);
@@ -714,6 +718,7 @@ function EditableText({
714
718
  const sel = window.getSelection();
715
719
  if (sel && !sel.isCollapsed) return;
716
720
  caretRef.current = caretOffsetFromPoint(e.clientX, e.clientY);
721
+ entryHeightRef.current = multiline ? e.currentTarget.getBoundingClientRect().height : null;
717
722
  setDraft(committedRef.current);
718
723
  draftRef.current = committedRef.current;
719
724
  setEditing(true);
@@ -781,9 +786,10 @@ function EditableText({
781
786
  };
782
787
  return multiline ? /* @__PURE__ */ jsx("textarea", { ...common, rows: 1 }) : /* @__PURE__ */ jsx("input", { ...common, type: "text" });
783
788
  }
784
- function autoSize(el) {
789
+ function autoSize(el, entryHeight) {
785
790
  el.style.height = "auto";
786
- el.style.height = el.scrollHeight + "px";
791
+ const nextHeight = el.scrollHeight;
792
+ el.style.height = entryHeight && Math.abs(nextHeight - entryHeight) <= 1 ? `${entryHeight}px` : `${nextHeight}px`;
787
793
  }
788
794
  function FormatToggle({
789
795
  value,