diff --git a/bun.lock b/bun.lock index 13ff972..3ea59d2 100644 --- a/bun.lock +++ b/bun.lock @@ -47,7 +47,7 @@ }, "apps/opencode-plugin": { "name": "@plannotator/opencode", - "version": "0.4.16", + "version": "0.6.4", "dependencies": { "@opencode-ai/plugin": "^1.0.218", }, @@ -117,7 +117,7 @@ }, "packages/server": { "name": "@plannotator/server", - "version": "0.4.16", + "version": "0.6.4", "peerDependencies": { "bun": ">=1.0.0", }, @@ -126,12 +126,12 @@ "name": "@plannotator/ui", "version": "0.0.1", "dependencies": { + "@plannotator/web-highlighter": "^0.8.1", "highlight.js": "^11.11.1", "perfect-freehand": "^1.2.2", "react": "^19.2.3", "react-dom": "^19.2.3", "unique-username-generator": "^1.5.1", - "web-highlighter": "^0.7.4", }, }, }, @@ -282,6 +282,8 @@ "@plannotator/ui": ["@plannotator/ui@workspace:packages/ui"], + "@plannotator/web-highlighter": ["@plannotator/web-highlighter@0.8.1", "", {}, "sha512-FlteNOwRj9iNSY/AhFMtqOnVS4FvsACvTw6IiOM1y8iDyhiU/WeZOgjURENvIY+wuUaiS9DDFmg0PrHMyuMR1Q=="], + "@rolldown/pluginutils": ["@rolldown/pluginutils@1.0.0-beta.53", "", {}, "sha512-vENRlFU4YbrwVqNDZ7fLvy+JR1CRkyr01jhSiDpE1u6py3OMzQfztQU2jxykW3ALNxO4kSlqIDeYyD0Y9RcQeQ=="], "@rollup/rollup-android-arm-eabi": ["@rollup/rollup-android-arm-eabi@4.54.0", "", { "os": "android", "cpu": "arm" }, "sha512-OywsdRHrFvCdvsewAInDKCNyR3laPA2mc9bRYJ6LBp5IyvF3fvXbbNR0bSzHlZVFtn6E0xw2oZlyjg4rKCVcng=="], @@ -588,8 +590,6 @@ "vite-plugin-singlefile": ["vite-plugin-singlefile@2.3.0", "", { "dependencies": { "micromatch": "^4.0.8" }, "peerDependencies": { "rollup": "^4.44.1", "vite": "^5.4.11 || ^6.0.0 || ^7.0.0" } }, "sha512-DAcHzYypM0CasNLSz/WG0VdKOCxGHErfrjOoyIPiNxTPTGmO6rRD/te93n1YL/s+miXq66ipF1brMBikf99c6A=="], - "web-highlighter": ["web-highlighter@0.7.4", "", {}, "sha512-07mWw6ib+Abcr/fuKEWYPy1Y0MsCOz6yUUVw9xMpyt5UzyXWtSlcwzy2YqnccCP/LjtM9MZHQSo3dbGJII8h6w=="], - "yallist": ["yallist@3.1.1", "", {}, "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="], "zod": ["zod@4.1.8", "", {}, "sha512-5R1P+WwQqmmMIEACyzSvo4JXHY5WiAFHRMg+zBZKgKS+Q1viRa0C1hmUKtHltoIFKtIdki3pRxkmpP74jnNYHQ=="], diff --git a/packages/ui/components/Viewer.tsx b/packages/ui/components/Viewer.tsx index 958b6d3..78904f1 100644 --- a/packages/ui/components/Viewer.tsx +++ b/packages/ui/components/Viewer.tsx @@ -1,5 +1,5 @@ import React, { useRef, useState, useEffect, forwardRef, useImperativeHandle, useCallback } from 'react'; -import Highlighter from 'web-highlighter'; +import Highlighter from '@plannotator/web-highlighter'; import hljs from 'highlight.js'; import 'highlight.js/styles/github-dark.css'; import { Block, Annotation, AnnotationType, EditorMode } from '../types'; @@ -137,6 +137,32 @@ export const Viewer = forwardRef(({ onAddAnnotationRef.current = onAddAnnotation; }, [onAddAnnotation]); + // Cmd+C / Ctrl+C keyboard shortcut for copying selected text + useEffect(() => { + const handleKeyDown = async (e: KeyboardEvent) => { + // Check for Cmd+C (Mac) or Ctrl+C (Windows/Linux) + if ((e.metaKey || e.ctrlKey) && e.key === 'c') { + // Don't intercept if typing in an input/textarea + const tag = (e.target as HTMLElement)?.tagName; + if (tag === 'INPUT' || tag === 'TEXTAREA') return; + + // If we have an active selection with captured text, use that + if (toolbarState?.selectionText) { + e.preventDefault(); + try { + await navigator.clipboard.writeText(toolbarState.selectionText); + } catch (err) { + console.error('Failed to copy:', err); + } + } + // Otherwise let the browser handle default copy behavior + } + }; + + document.addEventListener('keydown', handleKeyDown); + return () => document.removeEventListener('keydown', handleKeyDown); + }, [toolbarState]); + // Helper to create annotation from highlighter source const createAnnotationFromSource = ( highlighter: Highlighter, @@ -433,8 +459,9 @@ export const Viewer = forwardRef(({ window.getSelection()?.removeAllRanges(); } else { // Show toolbar in selection mode - // Capture selection text now (preserves line breaks between blocks) - const selectionText = window.getSelection()?.toString() || source.text; + // Use source.text from web-highlighter (complete text, captured before DOM modification) + // Note: Selection.toString() would be truncated since web-highlighter already wrapped the selection + const selectionText = source.text; pendingSourceRef.current = source; setToolbarState({ element: doms[0] as HTMLElement, source, selectionText }); } diff --git a/packages/ui/package.json b/packages/ui/package.json index c3816f9..a53c83a 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -14,6 +14,6 @@ "react": "^19.2.3", "react-dom": "^19.2.3", "unique-username-generator": "^1.5.1", - "web-highlighter": "^0.7.4" + "@plannotator/web-highlighter": "^0.8.1" } }