Skip to content

Commit 7817c46

Browse files
authored
fix: suppress native mobile context menu on text selection (#281)
1 parent 8b8487d commit 7817c46

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

packages/ui/components/Viewer.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,21 @@ export const Viewer = forwardRef<ViewerHandle, ViewerProps>(({
209209
onCodeBlockClick: handlePinpointCodeBlockClick,
210210
});
211211

212+
// Suppress native context menu on touch devices (prevents cut/copy/paste overlay on mobile)
213+
useEffect(() => {
214+
const container = containerRef.current;
215+
if (!container) return;
216+
const isTouchPrimary = window.matchMedia('(pointer: coarse)').matches;
217+
if (!isTouchPrimary) return;
218+
219+
const handleContextMenu = (e: Event) => {
220+
e.preventDefault();
221+
};
222+
223+
container.addEventListener('contextmenu', handleContextMenu);
224+
return () => container.removeEventListener('contextmenu', handleContextMenu);
225+
}, []);
226+
212227
// Detect when sticky action bar is "stuck" to show card background
213228
useEffect(() => {
214229
if (!stickyActions || !stickySentinelRef.current) return;
@@ -923,6 +938,7 @@ export const Viewer = forwardRef<ViewerHandle, ViewerProps>(({
923938
className={`w-full bg-card rounded-xl shadow-xl p-5 md:p-8 lg:p-10 xl:p-12 relative ${
924939
linkedDocInfo ? 'border-2 border-primary' : 'border border-border/50'
925940
} ${inputMethod === 'pinpoint' ? 'cursor-crosshair' : ''}`}
941+
style={{ WebkitTouchCallout: 'none' } as React.CSSProperties}
926942
>
927943
{/* Repo info + plan diff badge + demo badge + linked doc badge - top left */}
928944
{(repoInfo || hasPreviousVersion || showDemoBadge || linkedDocInfo) && (

0 commit comments

Comments
 (0)