Skip to content

Commit 42cc717

Browse files
bmiddhaCopilot
andauthored
[rush-serve-dashboard] Preserve Ctrl+A in dashboard text fields (#5918)
* fix(rush-serve): preserve text select-all Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * chore(rush-serve): add change file Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c3efd6e commit 42cc717

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

apps/rush-serve-dashboard/src/modules/mainBar.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export interface IMainBarActionWiringOptions {
2020
render: () => void;
2121
}
2222

23+
function isTextEditingTarget(target: EventTarget | undefined): boolean {
24+
return (
25+
target instanceof HTMLInputElement ||
26+
target instanceof HTMLTextAreaElement ||
27+
(target instanceof HTMLElement && target.isContentEditable)
28+
);
29+
}
30+
2331
export function wireMainBarActions(options: IMainBarActionWiringOptions): void {
2432
const {
2533
connect,
@@ -94,7 +102,7 @@ export function wireMainBarActions(options: IMainBarActionWiringOptions): void {
94102
}
95103

96104
window.addEventListener('keydown', (e: KeyboardEvent) => {
97-
if (e.key === 'a' && (e.metaKey || e.ctrlKey)) {
105+
if (e.key === 'a' && (e.metaKey || e.ctrlKey) && !isTextEditingTarget(e.target ?? undefined)) {
98106
e.preventDefault();
99107
setSelection(new Set(getOperationNames()));
100108
render();

apps/rush-serve-dashboard/src/test/actionWiring.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('action wiring', () => {
6565

6666
it('wires manager commands and keyboard selection', () => {
6767
document.body.innerHTML =
68-
'<button id="connect-btn"></button><button id="execute-btn"></button><button id="abort-execution-btn"></button>';
68+
'<button id="connect-btn"></button><button id="execute-btn"></button><button id="abort-execution-btn"></button><input id="name-search">';
6969
const debugBtn: HTMLButtonElement = document.createElement('button');
7070
const verboseBtn: HTMLButtonElement = document.createElement('button');
7171
const parallelismInput: HTMLInputElement = document.createElement('input');
@@ -100,6 +100,18 @@ describe('action wiring', () => {
100100
verboseBtn.click();
101101
parallelismInput.dispatchEvent(new Event('change'));
102102
playPauseBtn.click();
103+
const textField: HTMLInputElement = document.getElementById('name-search') as HTMLInputElement;
104+
const textFieldSelectAllEvent: KeyboardEvent = new KeyboardEvent('keydown', {
105+
key: 'a',
106+
ctrlKey: true,
107+
bubbles: true,
108+
cancelable: true
109+
});
110+
textField.dispatchEvent(textFieldSelectAllEvent);
111+
expect(textFieldSelectAllEvent.defaultPrevented).toBe(false);
112+
expect(setSelection).not.toHaveBeenCalled();
113+
expect(render).not.toHaveBeenCalled();
114+
103115
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'a', ctrlKey: true }));
104116
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
105117

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Allow Ctrl+A and Command+A to select text in Rush serve dashboard fields.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

0 commit comments

Comments
 (0)