From a7229e40f08a10f69027d6662c0c731420b1b54d Mon Sep 17 00:00:00 2001 From: ittoview Date: Mon, 9 Mar 2026 14:16:48 +0000 Subject: [PATCH] =?UTF-8?q?feat(=E7=BB=83=E4=B9=A0):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20Ctrl+H=20=E5=BF=AB=E6=8D=B7=E9=94=AE=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ProcessPracticePage: 按住 Ctrl+H 显示答案,松开隐藏 - ProcessDetailPage: 按住 Ctrl+H 显示答案,松开隐藏 - 解决手在键盘上时不方便点击屏幕查看答案的问题 via [HAPI](https://hapi.run) Co-Authored-By: HAPI --- src/pages/ProcessDetailPage.tsx | 33 +++++++++++++++++++++++++++++++ src/pages/ProcessPracticePage.tsx | 28 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/pages/ProcessDetailPage.tsx b/src/pages/ProcessDetailPage.tsx index ffea65b..b577e94 100644 --- a/src/pages/ProcessDetailPage.tsx +++ b/src/pages/ProcessDetailPage.tsx @@ -177,6 +177,39 @@ export function ProcessDetailPage() { // eslint-disable-next-line react-hooks/exhaustive-deps }, [id]) + // Ctrl+H 快捷键显示/隐藏答案 + useEffect(() => { + if (!isPracticeMode) return + + const handleKeyDown = (e: KeyboardEvent) => { + if (e.ctrlKey && e.key === 'h') { + e.preventDefault() + if (!showAnswer) { + setShowAnswer(true) + setInputLocked(true) + } + } + } + + const handleKeyUp = (e: KeyboardEvent) => { + if (e.key === 'Control' || e.key === 'h') { + if (showAnswer) { + setShowAnswer(false) + setInputLocked(false) + } + } + } + + window.addEventListener('keydown', handleKeyDown) + window.addEventListener('keyup', handleKeyUp) + + return () => { + window.removeEventListener('keydown', handleKeyDown) + window.removeEventListener('keyup', handleKeyUp) + } + }, [isPracticeMode, showAnswer]) + + // ── 验证逻辑 ────────────────────────────────────────────────────────────── const validateInput = useCallback( (input: string[]) => { diff --git a/src/pages/ProcessPracticePage.tsx b/src/pages/ProcessPracticePage.tsx index 4600def..3b0bcae 100644 --- a/src/pages/ProcessPracticePage.tsx +++ b/src/pages/ProcessPracticePage.tsx @@ -319,6 +319,34 @@ export default function ProcessPracticePage() { return () => clearTimeout(timer) }, [showAnswerForCell, restoreFocus]) + // Ctrl+H 快捷键显示/隐藏答案 + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.ctrlKey && e.key === 'h') { + e.preventDefault() + if (currentCellId && !showAnswerForCell) { + handleLongPress(currentCellId) + } + } + } + + const handleKeyUp = (e: KeyboardEvent) => { + if (e.key === 'Control' || e.key === 'h') { + if (showAnswerForCell) { + handleLongPressEnd() + } + } + } + + window.addEventListener('keydown', handleKeyDown) + window.addEventListener('keyup', handleKeyUp) + + return () => { + window.removeEventListener('keydown', handleKeyDown) + window.removeEventListener('keyup', handleKeyUp) + } + }, [currentCellId, showAnswerForCell, handleLongPress, handleLongPressEnd]) + // 点击格子切换(允许回顾已答对的格子) const handleCellClick = useCallback( (cellId: string) => {