diff --git a/.Jules/palette.md b/.Jules/palette.md index 9611477..71371f5 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -13,3 +13,7 @@ ## 2025-10-26 - Scratchpad Focus Management **Learning:** In VS Code Webviews, automatically returning focus to the main input (e.g. textarea) after a button click (like "Copy" or "Remove Empty Lines") can be disorienting for screen reader users and keyboard navigators. It interrupts the natural tab order and prevents users from hearing status updates on the button they just clicked. **Action:** Avoid calling `.focus()` on the input element immediately after secondary actions unless the primary purpose of the action is to prepare for immediate typing. For status updates (like "Copied!"), keep focus on the trigger element. + +## 2025-05-20 - Smart Copy Context Sensitivity +**Learning:** Users often select specific text expecting only that text to be copied, even if the general "Copy" button usually copies the entire document. Ignoring the selection in favor of a "Copy All" default feels like a loss of agency and utility. +**Action:** Implement "Smart Copy" logic in text-heavy interfaces: if text is selected, copy only the selection; otherwise, copy the full content. Provide clear feedback (e.g., "Copied Selection!") to confirm the action. diff --git a/src/features/scratchpad/scratchpad.html b/src/features/scratchpad/scratchpad.html index 5ccdfbf..ce6bf97 100644 --- a/src/features/scratchpad/scratchpad.html +++ b/src/features/scratchpad/scratchpad.html @@ -219,13 +219,24 @@ const content = textarea.value; if (!content) return; + let textToCopy = content; + let feedbackText = 'Copied!'; + let ariaLabel = 'Copied to Clipboard'; + + // Smart Copy: Copy selection if exists + if (textarea.selectionStart !== textarea.selectionEnd) { + textToCopy = content.substring(textarea.selectionStart, textarea.selectionEnd); + feedbackText = 'Copied Selection!'; + ariaLabel = 'Copied Selection to Clipboard'; + } + vscode.postMessage({ type: 'copyToClipboard', - content: content + content: textToCopy }); - btnCopy.textContent = 'Copied!'; - btnCopy.setAttribute('aria-label', 'Copied to Clipboard'); + btnCopy.textContent = feedbackText; + btnCopy.setAttribute('aria-label', ariaLabel); if (copyTimeoutId) clearTimeout(copyTimeoutId); copyTimeoutId = setTimeout(resetCopyButton, 2000);