Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/SplitPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,15 @@ export function SplitPane(props: SplitPaneProps) {
const createMouseDownHandler = useCallback(
(index: number) => (e: React.MouseEvent) => {
// Create a synthetic pointer event from the mouse event
// Spreading a SyntheticEvent only copies own properties,
// so preventDefault and stopPropagation must be re-bound.
const pointerEvent = {
...e,
pointerId: 1,
pointerType: 'mouse',
nativeEvent: e.nativeEvent,
preventDefault: e.preventDefault.bind(e),
stopPropagation: e.stopPropagation.bind(e),
} as unknown as React.PointerEvent;
handlePointerDown(index)(pointerEvent);
},
Expand All @@ -318,13 +322,16 @@ export function SplitPane(props: SplitPaneProps) {
const touch = e.touches[0];
if (!touch) return;
// Create a synthetic pointer event from the touch event
// See createMouseDownHandler for why preventDefault/stopPropagation are re-bound.
const pointerEvent = {
...e,
clientX: touch.clientX,
clientY: touch.clientY,
pointerId: touch.identifier,
pointerType: 'touch',
nativeEvent: e.nativeEvent,
preventDefault: e.preventDefault.bind(e),
stopPropagation: e.stopPropagation.bind(e),
} as unknown as React.PointerEvent;
handlePointerDown(index)(pointerEvent);
},
Expand Down
6 changes: 5 additions & 1 deletion src/hooks/useResizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ export function useResizer(options: UseResizerOptions): UseResizerResult {
const element = e.currentTarget as HTMLElement;

// Capture the pointer to receive all pointer events even if pointer leaves element
element.setPointerCapture(e.pointerId);
try {
element.setPointerCapture(e.pointerId);
} catch {
// Maybe a synthesized event, so ignore.
}

const pointerType = e.pointerType as 'mouse' | 'touch' | 'pen';

Expand Down