@37signals/lexxy 0.9.9-beta.preview3.domselection → 0.9.9-beta.preview4

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.
Files changed (2) hide show
  1. package/dist/lexxy.esm.js +19 -5
  2. package/package.json +1 -1
package/dist/lexxy.esm.js CHANGED
@@ -6512,6 +6512,15 @@ class EarlyEscapeCodeNode extends CodeNode {
6512
6512
  insertNewAfter(selection, restoreSelection) {
6513
6513
  if (!selection.isCollapsed()) return super.insertNewAfter(selection, restoreSelection)
6514
6514
 
6515
+ // Clamp element-type selection offsets that may have been invalidated
6516
+ // by the code retokenizer. The retokenizer's $updateAndRetainSelection
6517
+ // restores the element offset verbatim after re-tokenizing, but when
6518
+ // highlight splits changed the child count before retokenization, the
6519
+ // restored offset can exceed the current child count. Without clamping,
6520
+ // CodeNode.insertNewAfter passes the stale offset to splice(), which
6521
+ // throws "start + deleteCount > oldSize".
6522
+ this.#clampSelectionOffset(selection);
6523
+
6515
6524
  if (this.#isCursorAtStart(selection)) {
6516
6525
  this.insertBefore($createParagraphNode());
6517
6526
  return null
@@ -6528,6 +6537,15 @@ class EarlyEscapeCodeNode extends CodeNode {
6528
6537
  return super.insertNewAfter(selection, restoreSelection)
6529
6538
  }
6530
6539
 
6540
+ #clampSelectionOffset(selection) {
6541
+ const childrenSize = this.getChildrenSize();
6542
+ for (const point of [ selection.anchor, selection.focus ]) {
6543
+ if (point.type === "element" && point.key === this.__key && point.offset > childrenSize) {
6544
+ point.set(this.__key, childrenSize, "element");
6545
+ }
6546
+ }
6547
+ }
6548
+
6531
6549
  #isCursorAtStart(selection) {
6532
6550
  const { anchor } = selection;
6533
6551
  if (!$isAtNodeStart(anchor)) return false
@@ -6961,18 +6979,14 @@ class LexicalEditorElement extends HTMLElement {
6961
6979
  }
6962
6980
 
6963
6981
  set value(html) {
6964
- const editorHasFocus = isEditorFocused(this.editor);
6965
-
6966
6982
  this.editor.update(() => {
6967
- if (!editorHasFocus) $addUpdateTag(SKIP_DOM_SELECTION_TAG);
6968
-
6969
6983
  $getRoot()
6970
6984
  .clear()
6971
6985
  .selectEnd()
6972
6986
  .insertNodes(this.#parseHtmlIntoLexicalNodes(html));
6973
6987
 
6974
6988
  this.#toggleEmptyStatus();
6975
- }, { discrete: true });
6989
+ }, { discrete: true, tag: SKIP_DOM_SELECTION_TAG });
6976
6990
  }
6977
6991
 
6978
6992
  get canUndo() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@37signals/lexxy",
3
- "version": "0.9.9-beta.preview3.domselection",
3
+ "version": "0.9.9-beta.preview4",
4
4
  "description": "Lexxy - A modern rich text editor for Rails.",
5
5
  "module": "dist/lexxy.esm.js",
6
6
  "type": "module",