From 9b2cfea0c13fef048ba6ae3d5281d1eea836e9b3 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Wed, 27 Mar 2024 19:22:26 -0400
Subject: preserve nodeSelections after onBlur by not calling autoLink.  fix
 promoting text to list cursor locatoin

---
 .../views/nodes/formattedText/FormattedTextBox.tsx | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

(limited to 'src/client/views/nodes/formattedText/FormattedTextBox.tsx')

diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index 9882a9be9..d25101844 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -1694,8 +1694,10 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB
                         this._editorView.dispatch(this._editorView.state.tr.setSelection(new NodeSelection(selectOrderedList ? $olistPos! : listPos!)));
                     } else {
                         const nodePos = clickPosVal - (olistPos === clickPosVal ? 0 : 1);
-                        const tr = this._editorView.state.tr.setNodeMarkup(nodePos, listNode.type, { ...listNode.attrs, visibility: !listNode.attrs.visibility });
-                        this._editorView.dispatch(tr.setSelection(TextSelection.create(tr.doc, nodePos)));
+                        if (this._editorView.state.doc.nodeAt(nodePos)) {
+                            const tr = this._editorView.state.tr.setNodeMarkup(nodePos, listNode.type, { ...listNode.attrs, visibility: !listNode.attrs.visibility });
+                            this._editorView.dispatch(tr.setSelection(TextSelection.create(tr.doc, nodePos)));
+                        }
                     }
                 }
                 addStyleSheetRule(FormattedTextBox._bulletStyleSheet, olistNode.attrs.mapStyle + olistNode.attrs.bulletStyle + ':hover:before', { background: 'gray' });
@@ -1715,13 +1717,15 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB
         if (this.ProseRef?.children[0] !== e.nativeEvent.target) return;
         if (!(this.EditorView?.state.selection instanceof NodeSelection) || this.EditorView.state.selection.node.type !== this.EditorView.state.schema.nodes.footnote) {
             const stordMarks = this._editorView?.state.storedMarks?.slice();
-            this.autoLink();
-            if (this._editorView?.state.tr) {
-                const tr = stordMarks?.reduce((tr, m) => {
-                    tr.addStoredMark(m);
-                    return tr;
-                }, this._editorView.state.tr);
-                tr && this._editorView.dispatch(tr);
+            if (!(this.EditorView?.state.selection instanceof NodeSelection)) {
+                this.autoLink();
+                if (this._editorView?.state.tr) {
+                    const tr = stordMarks?.reduce((tr, m) => {
+                        tr.addStoredMark(m);
+                        return tr;
+                    }, this._editorView.state.tr);
+                    tr && this._editorView.dispatch(tr);
+                }
             }
         }
         if (RichTextMenu.Instance?.view === this._editorView && !this._props.rootSelected?.()) {
-- 
cgit v1.2.3-70-g09d2

