|
72 | 72 | outline: 1px solid var(--vscode-focusBorder); |
73 | 73 | outline-offset: 1px; |
74 | 74 | } |
| 75 | + .btn:disabled { |
| 76 | + opacity: 0.5; |
| 77 | + cursor: not-allowed; |
| 78 | + } |
75 | 79 |
|
76 | 80 | /* Secondary Button (Standard) */ |
77 | 81 | .btn-secondary { |
78 | 82 | color: var(--vscode-button-secondaryForeground); |
79 | 83 | background-color: var(--vscode-button-secondaryBackground); |
80 | 84 | } |
81 | | - .btn-secondary:hover { |
| 85 | + .btn-secondary:not(:disabled):hover { |
82 | 86 | background-color: var(--vscode-button-secondaryHoverBackground); |
83 | 87 | } |
84 | 88 | /* Destructive State for Secondary Button */ |
|
95 | 99 | color: var(--vscode-button-foreground); |
96 | 100 | background-color: var(--vscode-button-background); |
97 | 101 | } |
98 | | - .btn-primary:hover { |
| 102 | + .btn-primary:not(:disabled):hover { |
99 | 103 | background-color: var(--vscode-button-hoverBackground); |
100 | 104 | } |
101 | 105 | </style> |
|
106 | 110 | aria-label="Scratchpad Input" |
107 | 111 | placeholder="Scratchpad: Type your temporary notes here... (Content is cleared on reload)" |
108 | 112 | spellcheck="false" |
| 113 | + autofocus |
109 | 114 | ></textarea> |
110 | 115 | <div class="footer"> |
111 | 116 | <span id="char-count" class="char-count" aria-live="polite">0 chars</span> |
|
146 | 151 | charCount.textContent = `${length} char${length !== 1 ? 's' : ''}`; |
147 | 152 | } |
148 | 153 |
|
| 154 | + function updateButtonStates() { |
| 155 | + const hasContent = textarea.value.length > 0; |
| 156 | + btnCopy.disabled = !hasContent; |
| 157 | + btnRemoveEmpty.disabled = !hasContent; |
| 158 | + // Clear button should also be disabled if there's no content |
| 159 | + // However, we need to respect the "confirm" state if it was active, |
| 160 | + // but if content is empty, confirm state is irrelevant as we can't clear empty. |
| 161 | + // If we just cleared it, it becomes disabled. |
| 162 | + btnClear.disabled = !hasContent; |
| 163 | + |
| 164 | + // If disabled, we should probably reset any pending states (like Confirm?) |
| 165 | + // to avoid weird states when re-enabling. |
| 166 | + if (!hasContent) { |
| 167 | + if (btnClear.dataset.state === 'confirm') { |
| 168 | + resetClearButton(); |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + |
149 | 173 | function resetClearButton() { |
150 | 174 | if (clearTimeoutId) { |
151 | 175 | clearTimeout(clearTimeoutId); |
|
185 | 209 |
|
186 | 210 | textarea.addEventListener('input', () => { |
187 | 211 | updateCharCount(); |
| 212 | + updateButtonStates(); |
188 | 213 | onInput(); |
189 | 214 | }); |
190 | 215 |
|
|
224 | 249 | // Second click: Perform action |
225 | 250 | textarea.value = ''; |
226 | 251 | updateCharCount(); |
| 252 | + updateButtonStates(); |
227 | 253 | onInput(); |
228 | 254 | textarea.focus(); |
229 | 255 | resetClearButton(); |
|
247 | 273 | } else { |
248 | 274 | textarea.value = newContent; |
249 | 275 | updateCharCount(); |
| 276 | + updateButtonStates(); |
250 | 277 | onInput(); |
251 | 278 |
|
252 | 279 | const removedCount = lines.length - nonEmptyLines.length; |
|
269 | 296 | case 'restoreContent': |
270 | 297 | textarea.value = message.content; |
271 | 298 | updateCharCount(); |
| 299 | + updateButtonStates(); |
272 | 300 | break; |
273 | 301 | } |
274 | 302 | }); |
| 303 | + |
| 304 | + // Initialize button states |
| 305 | + updateButtonStates(); |
275 | 306 | </script> |
276 | 307 | </body> |
277 | 308 | </html> |
0 commit comments