|
56 | 56 | display: flex; |
57 | 57 | gap: 8px; |
58 | 58 | } |
59 | | - .btn-clear { |
| 59 | + .btn { |
60 | 60 | background: none; |
61 | 61 | border: none; |
62 | 62 | cursor: pointer; |
63 | | - color: var(--vscode-button-foreground); |
64 | | - background-color: var(--vscode-button-secondaryBackground); |
65 | 63 | padding: 2px 6px; |
66 | 64 | border-radius: 2px; |
67 | 65 | font-size: 11px; |
68 | 66 | display: flex; |
69 | 67 | align-items: center; |
70 | 68 | gap: 4px; |
| 69 | + font-family: var(--vscode-font-family); |
71 | 70 | } |
72 | | - .btn-clear:hover { |
73 | | - background-color: var(--vscode-button-secondaryHoverBackground); |
74 | | - } |
75 | | - .btn-clear:focus { |
| 71 | + .btn:focus { |
76 | 72 | outline: 1px solid var(--vscode-focusBorder); |
77 | 73 | outline-offset: 1px; |
78 | 74 | } |
79 | | - .btn-clear.confirm { |
| 75 | + |
| 76 | + /* Secondary Button (Standard) */ |
| 77 | + .btn-secondary { |
| 78 | + color: var(--vscode-button-secondaryForeground); |
| 79 | + background-color: var(--vscode-button-secondaryBackground); |
| 80 | + } |
| 81 | + .btn-secondary:hover { |
| 82 | + background-color: var(--vscode-button-secondaryHoverBackground); |
| 83 | + } |
| 84 | + /* Destructive State for Secondary Button */ |
| 85 | + .btn-secondary.confirm { |
80 | 86 | background-color: var(--vscode-button-destructiveBackground); |
81 | 87 | color: var(--vscode-button-destructiveForeground); |
82 | 88 | } |
83 | | - .btn-clear.confirm:hover { |
| 89 | + .btn-secondary.confirm:hover { |
84 | 90 | background-color: var(--vscode-button-destructiveHoverBackground); |
85 | 91 | } |
| 92 | + |
| 93 | + /* Primary Button */ |
| 94 | + .btn-primary { |
| 95 | + color: var(--vscode-button-foreground); |
| 96 | + background-color: var(--vscode-button-background); |
| 97 | + } |
| 98 | + .btn-primary:hover { |
| 99 | + background-color: var(--vscode-button-hoverBackground); |
| 100 | + } |
86 | 101 | </style> |
87 | 102 | </head> |
88 | 103 | <body> |
|
95 | 110 | <div class="footer"> |
96 | 111 | <span id="char-count" class="char-count" aria-live="polite">0 chars</span> |
97 | 112 | <div class="actions"> |
98 | | - <button id="btn-clear" class="btn-clear" aria-label="Clear Scratchpad" title="Clear all content"> |
| 113 | + <button id="btn-copy" class="btn btn-primary" aria-label="Copy to Clipboard" title="Copy content to clipboard"> |
| 114 | + Copy |
| 115 | + </button> |
| 116 | + <button id="btn-clear" class="btn btn-secondary" aria-label="Clear Scratchpad" title="Clear all content"> |
99 | 117 | Clear |
100 | 118 | </button> |
101 | 119 | </div> |
|
105 | 123 | const textarea = document.getElementById('scratchpad'); |
106 | 124 | const charCount = document.getElementById('char-count'); |
107 | 125 | const btnClear = document.getElementById('btn-clear'); |
| 126 | + const btnCopy = document.getElementById('btn-copy'); |
108 | 127 | let clearTimeoutId; |
| 128 | + let copyTimeoutId; |
109 | 129 |
|
110 | 130 | // Debounce function |
111 | 131 | function debounce(func, delay) { |
|
132 | 152 | btnClear.dataset.state = 'idle'; |
133 | 153 | } |
134 | 154 |
|
| 155 | + function resetCopyButton() { |
| 156 | + if (copyTimeoutId) { |
| 157 | + clearTimeout(copyTimeoutId); |
| 158 | + copyTimeoutId = null; |
| 159 | + } |
| 160 | + btnCopy.textContent = 'Copy'; |
| 161 | + btnCopy.setAttribute('aria-label', 'Copy to Clipboard'); |
| 162 | + } |
| 163 | + |
135 | 164 | // 监听内容变化 |
136 | 165 | const onInput = debounce(() => { |
137 | 166 | vscode.postMessage({ |
|
145 | 174 | onInput(); |
146 | 175 | }); |
147 | 176 |
|
| 177 | + // Copy Button Logic |
| 178 | + btnCopy.addEventListener('click', () => { |
| 179 | + const content = textarea.value; |
| 180 | + if (!content) return; |
| 181 | + |
| 182 | + vscode.postMessage({ |
| 183 | + type: 'copyToClipboard', |
| 184 | + content: content |
| 185 | + }); |
| 186 | + |
| 187 | + btnCopy.textContent = 'Copied!'; |
| 188 | + btnCopy.setAttribute('aria-label', 'Copied to Clipboard'); |
| 189 | + |
| 190 | + if (copyTimeoutId) clearTimeout(copyTimeoutId); |
| 191 | + copyTimeoutId = setTimeout(resetCopyButton, 2000); |
| 192 | + |
| 193 | + textarea.focus(); |
| 194 | + }); |
| 195 | + |
| 196 | + // Clear Button Logic |
148 | 197 | btnClear.addEventListener('click', () => { |
149 | 198 | if (textarea.value.length === 0) return; |
150 | 199 |
|
|
0 commit comments