Skip to content

Commit 0cc2301

Browse files
feat(scratchpad): add text selection statistics to status bar
- Update scratchpad footer to display character count of selected text - Add event listeners (mouseup, keyup, focus) to trigger status updates - Improve accessibility by providing more context on text selection
1 parent fced1d9 commit 0cc2301

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/features/scratchpad/scratchpad.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,16 @@
149149
function updateCharCount() {
150150
const length = textarea.value.length;
151151
const lines = length === 0 ? 0 : textarea.value.split('\n').length;
152-
charCount.textContent = `${length} char${length !== 1 ? 's' : ''}, ${lines} line${lines !== 1 ? 's' : ''}`;
152+
153+
const start = textarea.selectionStart;
154+
const end = textarea.selectionEnd;
155+
const selectionLen = Math.abs(end - start);
156+
157+
let status = `${length} char${length !== 1 ? 's' : ''}, ${lines} line${lines !== 1 ? 's' : ''}`;
158+
if (selectionLen > 0) {
159+
status += ` (${selectionLen} selected)`;
160+
}
161+
charCount.textContent = status;
153162
}
154163

155164
function updateButtonStates() {
@@ -214,6 +223,11 @@
214223
onInput();
215224
});
216225

226+
// Update selection stats
227+
['mouseup', 'keyup', 'focus'].forEach(event => {
228+
textarea.addEventListener(event, updateCharCount);
229+
});
230+
217231
// Copy Button Logic
218232
btnCopy.addEventListener('click', () => {
219233
const start = textarea.selectionStart;

0 commit comments

Comments
 (0)