fix(ui): paint composer caret on first padding click (#2509)

This commit is contained in:
Ibrahim Khan
2026-07-30 19:44:52 +03:00
committed by GitHub
parent 80d939cccd
commit 5792a3d2e2
4 changed files with 128 additions and 11 deletions
@@ -0,0 +1,25 @@
import type { EditorView } from '@codemirror/view';
import type { MouseEvent } from 'react';
type ComposerHostMouseDownEvent = Pick<
MouseEvent,
'target' | 'clientX' | 'clientY' | 'preventDefault'
>;
export function handleComposerHostMouseDown(
view: EditorView | null,
event: ComposerHostMouseDownEvent,
): void {
if (!view || view.state.readOnly || !view.contentDOM.isContentEditable) return;
// A click that already landed in the text needs no help, and
// forwarding it would break drag-selection.
if (view.contentDOM.contains(event.target as Node)) return;
event.preventDefault();
const position = view.posAtCoords({ x: event.clientX, y: event.clientY })
?? view.state.doc.length;
// Focus before dispatching so CodeMirror updates the drawn caret's
// visibility while applying the selection update.
view.focus();
view.dispatch({ selection: { anchor: position } });
}