fix: disable click-to-seek handlers on mobile devices

- Prevent interference with native text selection on touch devices
- Remove click listeners for timestamps/words when isMobile is true
This commit is contained in:
rishikanthc
2025-12-12 14:57:03 -08:00
committed by Rishikanth Chandrasekaran
parent 67648c7c3a
commit c33197752b
2 changed files with 7 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import { forwardRef, useRef, useState, useCallback, useEffect, useMemo } from 'react';
import { useKaraokeHighlight, computeWordOffsets, findActiveWordIndex } from '@/features/transcription/hooks/useKaraokeHighlight';
import { cn } from '@/lib/utils';
import { useIsMobile } from '@/hooks/use-mobile';
import type { Note } from '@/types/note';
// Helper for cross-browser caret position
@@ -71,6 +72,7 @@ export const TranscriptView = forwardRef<HTMLDivElement, TranscriptViewProps>(({
const containerRef = useRef<HTMLDivElement>(null);
const [isModifierPressed, setIsModifierPressed] = useState(false);
const isMobile = useIsMobile();
// Use CSS Highlight API for Compact Mode
// Note: We only use this hook when in compact mode to save resources
@@ -134,10 +136,10 @@ export const TranscriptView = forwardRef<HTMLDivElement, TranscriptViewProps>(({
return (
<div
ref={containerRef}
onClick={handleWordClick}
onClick={isMobile ? undefined : handleWordClick}
className={cn(
"text-lg leading-relaxed text-carbon-700 dark:text-carbon-300 whitespace-pre-wrap font-reading selection:bg-orange-500/30 transition-colors duration-200 select-text",
isModifierPressed ? 'cursor-pointer hover:text-carbon-900 dark:hover:text-carbon-100' : 'cursor-text'
!isMobile && isModifierPressed ? 'cursor-pointer hover:text-carbon-900 dark:hover:text-carbon-100' : 'cursor-text'
)}
>
{/* The hook returns the built text string, so we just render it directly */}
@@ -268,10 +270,10 @@ export const TranscriptView = forwardRef<HTMLDivElement, TranscriptViewProps>(({
{/* Text */}
<div
ref={(el) => { segmentRefs.current[i] = el; }}
onClick={(e) => handleExpandedClick(e, i)}
onClick={isMobile ? undefined : (e) => handleExpandedClick(e, i)}
className={cn(
"flex-grow text-base text-primary leading-relaxed whitespace-pre-wrap font-reading transition-colors duration-200 select-text",
isModifierPressed ? 'cursor-pointer hover:text-carbon-900 dark:hover:text-carbon-100' : 'cursor-text'
!isMobile && isModifierPressed ? 'cursor-pointer hover:text-carbon-900 dark:hover:text-carbon-100' : 'cursor-text'
)}
>
{segment.fullText || segment.text}

View File

@@ -99,8 +99,8 @@ export function TranscriptSection({
}
}, [currentWordIndex, autoScrollEnabled]);
// Click to seek handler
useEffect(() => {
if (isMobile) return; // Disable click-to-seek globally on mobile to prevent selection interference
const el = transcriptRef.current;
if (!el) return;
const onClick = (e: MouseEvent) => {