Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/rush-serve-dashboard/src/modules/mainBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export interface IMainBarActionWiringOptions {
render: () => void;
}

function isTextEditingTarget(target: EventTarget | undefined): boolean {
return (
target instanceof HTMLInputElement ||
target instanceof HTMLTextAreaElement ||
(target instanceof HTMLElement && target.isContentEditable)
);
}

export function wireMainBarActions(options: IMainBarActionWiringOptions): void {
const {
connect,
Expand Down Expand Up @@ -94,7 +102,7 @@ export function wireMainBarActions(options: IMainBarActionWiringOptions): void {
}

window.addEventListener('keydown', (e: KeyboardEvent) => {
if (e.key === 'a' && (e.metaKey || e.ctrlKey)) {
if (e.key === 'a' && (e.metaKey || e.ctrlKey) && !isTextEditingTarget(e.target ?? undefined)) {
e.preventDefault();
setSelection(new Set(getOperationNames()));
render();
Expand Down
14 changes: 13 additions & 1 deletion apps/rush-serve-dashboard/src/test/actionWiring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('action wiring', () => {

it('wires manager commands and keyboard selection', () => {
document.body.innerHTML =
'<button id="connect-btn"></button><button id="execute-btn"></button><button id="abort-execution-btn"></button>';
'<button id="connect-btn"></button><button id="execute-btn"></button><button id="abort-execution-btn"></button><input id="name-search">';
const debugBtn: HTMLButtonElement = document.createElement('button');
const verboseBtn: HTMLButtonElement = document.createElement('button');
const parallelismInput: HTMLInputElement = document.createElement('input');
Expand Down Expand Up @@ -100,6 +100,18 @@ describe('action wiring', () => {
verboseBtn.click();
parallelismInput.dispatchEvent(new Event('change'));
playPauseBtn.click();
const textField: HTMLInputElement = document.getElementById('name-search') as HTMLInputElement;
const textFieldSelectAllEvent: KeyboardEvent = new KeyboardEvent('keydown', {
key: 'a',
ctrlKey: true,
bubbles: true,
cancelable: true
});
textField.dispatchEvent(textFieldSelectAllEvent);
expect(textFieldSelectAllEvent.defaultPrevented).toBe(false);
expect(setSelection).not.toHaveBeenCalled();
expect(render).not.toHaveBeenCalled();

window.dispatchEvent(new KeyboardEvent('keydown', { key: 'a', ctrlKey: true }));
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Allow Ctrl+A and Command+A to select text in Rush serve dashboard fields.",
"type": "patch"
}
],
"packageName": "@microsoft/rush"
}