fix(ui): paint composer caret on first padding click (#2509)
This commit is contained in:
@@ -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 } });
|
||||
}
|
||||
Reference in New Issue
Block a user