Skip to content

Commit 6ef2aea

Browse files
feat(super-editor): add pointer event observability (#2801)
1 parent 1d3d77a commit 6ef2aea

5 files changed

Lines changed: 58 additions & 1 deletion

File tree

packages/super-editor/src/editors/v1/core/Editor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ export class Editor extends EventEmitter<EditorEventMap> {
426426
onCommentsLoaded: () => null,
427427
onCommentClicked: () => null,
428428
onCommentLocationsUpdate: () => null,
429+
onPointerDown: () => null,
430+
onPointerUp: () => null,
431+
onRightClick: () => null,
429432
onDocumentLocked: () => null,
430433
onFirstRender: () => null,
431434
onCollaborationReady: () => null,
@@ -763,6 +766,9 @@ export class Editor extends EventEmitter<EditorEventMap> {
763766
this.on('list-definitions-change', this.options.onListDefinitionsChange!);
764767
this.on('fonts-resolved', this.options.onFontsResolved!);
765768
this.on('exception', this.options.onException!);
769+
this.on('pointerDown', this.options.onPointerDown!);
770+
this.on('pointerUp', this.options.onPointerUp!);
771+
this.on('rightClick', this.options.onRightClick!);
766772
}
767773

768774
/**
@@ -1161,6 +1167,9 @@ export class Editor extends EventEmitter<EditorEventMap> {
11611167
this.on('list-definitions-change', this.options.onListDefinitionsChange!);
11621168
this.on('fonts-resolved', this.options.onFontsResolved!);
11631169
this.on('exception', this.options.onException!);
1170+
this.on('pointerDown', this.options.onPointerDown!);
1171+
this.on('pointerUp', this.options.onPointerUp!);
1172+
this.on('rightClick', this.options.onRightClick!);
11641173

11651174
if (!shouldMountRenderer) {
11661175
this.#emitCreateAsync();
@@ -1237,6 +1246,9 @@ export class Editor extends EventEmitter<EditorEventMap> {
12371246
this.on('commentClick', this.options.onCommentClicked!);
12381247
this.on('locked', this.options.onDocumentLocked!);
12391248
this.on('list-definitions-change', this.options.onListDefinitionsChange!);
1249+
this.on('pointerDown', this.options.onPointerDown!);
1250+
this.on('pointerUp', this.options.onPointerUp!);
1251+
this.on('rightClick', this.options.onRightClick!);
12401252

12411253
if (!shouldMountRenderer) {
12421254
this.#emitCreateAsync();

packages/super-editor/src/editors/v1/core/presentation-editor/pointer-events/EditorInputManager.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,16 @@ export class EditorInputManager {
12731273
#handlePointerDown(event: PointerEvent): void {
12741274
if (!this.#deps) return;
12751275

1276+
// Emit local-only pointer events for external consumers (e.g. debugging trackpad issues)
1277+
// Emit directly on the Editor instance so consumers can use editor.on('pointerDown', ...)
1278+
const bodyEditor = this.#deps.getEditor();
1279+
bodyEditor.emit?.('pointerDown', { editor: bodyEditor, event });
1280+
1281+
// Emit rightClick for secondary button (button 2) or Ctrl+Click on Mac
1282+
if (event.button === 2 || (event.ctrlKey && navigator.platform.includes('Mac'))) {
1283+
bodyEditor.emit?.('rightClick', { editor: bodyEditor, event });
1284+
}
1285+
12761286
// Return early for non-left clicks
12771287
if (event.button !== 0) return;
12781288

@@ -1304,7 +1314,6 @@ export class EditorInputManager {
13041314
return;
13051315
}
13061316

1307-
const bodyEditor = this.#deps.getEditor();
13081317
const layoutState = this.#deps.getLayoutState();
13091318
const clickedNoteTarget = this.#resolveRenderedNoteTargetAtPointer(target, event.clientX, event.clientY);
13101319

@@ -1676,6 +1685,11 @@ export class EditorInputManager {
16761685
#handlePointerUp(event: PointerEvent): void {
16771686
if (!this.#deps) return;
16781687

1688+
// Emit local-only pointer event for external consumers (e.g. debugging trackpad issues)
1689+
// Emit directly on the Editor instance so consumers can use editor.on('pointerUp', ...)
1690+
const editor = this.#deps.getEditor();
1691+
editor.emit?.('pointerUp', { editor, event });
1692+
16791693
this.#suppressFocusInFromDraggable = false;
16801694

16811695
if (!this.#isDragging) {

packages/super-editor/src/editors/v1/core/types/EditorConfig.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,15 @@ export interface EditorOptions {
564564
/** Host-provided permission hook */
565565
permissionResolver?: ((params: PermissionParams) => boolean | undefined) | null;
566566

567+
/** Called on pointer down events (local only, not broadcast via collaboration) */
568+
onPointerDown?: (params: { editor: Editor; event: PointerEvent }) => void;
569+
570+
/** Called on pointer up events (local only, not broadcast via collaboration) */
571+
onPointerUp?: (params: { editor: Editor; event: PointerEvent }) => void;
572+
573+
/** Called on right-click (local only, not broadcast via collaboration) */
574+
onRightClick?: (params: { editor: Editor; event: PointerEvent }) => void;
575+
567576
/**
568577
* Custom resolver for the link click popover.
569578
* Called when a user clicks a link to determine which popover to show.

packages/super-editor/src/editors/v1/core/types/EditorEvents.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,13 @@ export interface EditorEventMap extends DefaultEventMap {
221221
* more story caches are invalidated.
222222
*/
223223
'tracked-changes-changed': [TrackedChangesChangedPayload];
224+
225+
/** Called on pointer down (local only, not broadcast via collaboration) */
226+
pointerDown: [{ editor: Editor; event: PointerEvent }];
227+
228+
/** Called on pointer up (local only, not broadcast via collaboration) */
229+
pointerUp: [{ editor: Editor; event: PointerEvent }];
230+
231+
/** Called on right-click (local only, not broadcast via collaboration) */
232+
rightClick: [{ editor: Editor; event: PointerEvent }];
224233
}

packages/superdoc/src/dev/components/SuperdocDev.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,19 @@ const onEditorCreate = ({ editor }) => {
11021102
editor.on('fieldAnnotationDoubleClicked', (params) => {
11031103
console.log('fieldAnnotationDoubleClicked', { params });
11041104
});
1105+
1106+
// SD-2494: Pointer event observability for debugging trackpad/right-click selection issues
1107+
editor.on('pointerDown', (params) => {
1108+
console.log('pointerDown', { params });
1109+
});
1110+
1111+
editor.on('pointerUp', (params) => {
1112+
console.log('pointerUp', { params });
1113+
});
1114+
1115+
editor.on('rightClick', (params) => {
1116+
console.log('rightClick', { params });
1117+
});
11051118
};
11061119
11071120
watch(

0 commit comments

Comments
 (0)