Keep a link click in a table cell that just got focus

A click on a link in a focused table cell could be lost on a busy
computer. ProseMirror reads a click on the next selectionchange. Its
delayed focus check could run first and restore the old selection, and
the link source did not open.

- The mousedown handler sets the clicked position at once.

The linkClickAfterFocus smoke test forces this order of events.
This commit is contained in:
Knotty Wyvern
2026-11-04 21:41:21 -07:00
parent 2b28707ba0
commit bfb549fd02
2 changed files with 69 additions and 0 deletions
+7
View File
@@ -451,6 +451,13 @@ export function tableControls(root: HTMLElement, view: EditorView, initialSource
event.preventDefault(); activate(cell);
const hit = editor?.view.posAtCoords({ left: event.clientX, top: event.clientY });
if (hit) { editor?.commands.setTextSelection(hit.pos); editor?.view.focus(); }
} else if (event.detail === 1 && editor && !editor.view.composing && editor.view.dom.contains(event.target)) {
// ProseMirror reads a native click on the next selectionchange. Its
// delayed focus check can run first and restore the old selection, so
// the click is lost under load. Set the clicked position here. The
// browser then places the same caret, and a drag starts from it.
const hit = editor.view.posAtCoords({ left: event.clientX, top: event.clientY });
if (hit) editor.commands.setTextSelection(hit.pos);
}
});
refreshFormulas();