Skip to content

Commit bdf44d3

Browse files
Nancy LiDevtools-frontend LUCI CQ
authored andcommitted
[RPP Icicle blowtorch] Clear the input when user press the escape
Also fix the problem that 'Escape' will close the dialog Fixed:382484865 Change-Id: Ibd7ce98e6b0167ec79ccd88519c7fd51e89dda04 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6076624 Commit-Queue: Nancy Li <[email protected]> Reviewed-by: Jack Franklin <[email protected]>
1 parent 3257998 commit bdf44d3

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

front_end/panels/timeline/TimelineUIUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ export class TimelineUIUtils {
19791979
});
19801980

19811981
link.addEventListener('keydown', event => {
1982-
if (event.key === 'Enter') {
1982+
if (event.key === Platform.KeyboardUtilities.ENTER_KEY) {
19831983
TimelinePanel.instance().select(selectionFromEvent(entry));
19841984
event.consume(true);
19851985
}
@@ -2172,7 +2172,7 @@ export class TimelineUIUtils {
21722172
container.tabIndex = 0;
21732173
container.addEventListener('click', () => TimelinePanel.instance().select(selectionFromEvent(event)), false);
21742174
container.addEventListener('keydown', keyEvent => {
2175-
if (keyEvent.key === 'Enter') {
2175+
if (keyEvent.key === Platform.KeyboardUtilities.ENTER_KEY) {
21762176
TimelinePanel.instance().select(selectionFromEvent(event));
21772177
keyEvent.consume(true);
21782178
}

front_end/panels/timeline/components/IgnoreListSetting.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
// found in the LICENSE file.
44

55
import * as Common from '../../../core/common/common.js';
6+
import * as Platform from '../../../core/platform/platform.js';
67
import * as SDK from '../../../core/sdk/sdk.js';
78
import * as Bindings from '../../../models/bindings/bindings.js';
89
import * as Workspace from '../../../models/workspace/workspace.js';
910
import {
1011
dispatchBlurEvent,
1112
dispatchFocusEvent,
1213
dispatchInputEvent,
14+
dispatchKeyDownEvent,
1315
renderElementIntoDOM,
1416
} from '../../../testing/DOMHelpers.js';
1517
import {describeWithEnvironment} from '../../../testing/EnvironmentHelpers.js';
@@ -324,6 +326,18 @@ describeWithEnvironment('Ignore List Setting', () => {
324326
// When add an invalid rule, the temp regex will be removed.
325327
assert.strictEqual(regexPatterns.length, 3);
326328
});
329+
330+
it('Clear the input when `Escape` is pressed', async () => {
331+
const component = await renderIgnoreListSetting();
332+
const newRegexInput = getNewRegexInput(component);
333+
334+
// This is a duplicate rule, so it is invalid.
335+
newRegexInput.value = 'rule 2';
336+
337+
dispatchKeyDownEvent(newRegexInput, {key: Platform.KeyboardUtilities.ESCAPE_KEY});
338+
// When add an invalid rule, the temp regex will be removed.
339+
assert.strictEqual('', newRegexInput.value);
340+
});
327341
});
328342
});
329343

front_end/panels/timeline/components/IgnoreListSetting.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import '../../../ui/components/menus/menus.js';
66

77
import * as Common from '../../../core/common/common.js';
88
import * as i18n from '../../../core/i18n/i18n.js';
9+
import * as Platform from '../../../core/platform/platform.js';
910
import * as Bindings from '../../../models/bindings/bindings.js';
1011
import * as Buttons from '../../../ui/components/buttons/buttons.js';
1112
import * as Dialogs from '../../../ui/components/dialogs/dialogs.js';
@@ -146,7 +147,7 @@ export class IgnoreListSetting extends HTMLElement {
146147
this.#newRegexInput.value = '';
147148
}
148149

149-
#onNewRegexAdded(): void {
150+
#addNewRegexToIgnoreList(): void {
150151
const newRegex = this.#newRegexInput.value.trim();
151152

152153
this.#finishEditing();
@@ -160,12 +161,23 @@ export class IgnoreListSetting extends HTMLElement {
160161
}
161162

162163
#handleKeyDown(event: KeyboardEvent): void {
163-
// When user press the 'Enter' or 'Escape', the current regex will be added and user can keep adding more regexes.
164-
if (event.key === 'Enter' || event.key === 'Escape') {
165-
this.#onNewRegexAdded();
164+
// When user press the 'Enter', the current regex will be added and user can keep adding more regexes.
165+
if (event.key === Platform.KeyboardUtilities.ENTER_KEY) {
166+
this.#addNewRegexToIgnoreList();
166167
this.#startEditing();
167168
return;
168169
}
170+
171+
// When user press the 'Escape', it means cancel the editing, so the current regex won't be added and the input will
172+
// lose focus.
173+
if (event.key === Platform.KeyboardUtilities.ESCAPE_KEY) {
174+
// Escape key will close the dialog, and toggle the `Console` drawer. So we need to ignore other listeners.
175+
event.stopImmediatePropagation();
176+
177+
this.#finishEditing();
178+
this.#resetInput();
179+
this.#newRegexInput.blur();
180+
}
169181
}
170182

171183
/**
@@ -208,7 +220,7 @@ export class IgnoreListSetting extends HTMLElement {
208220
UI.Tooltip.Tooltip.install(this.#newRegexCheckbox, checkboxHelpText);
209221
UI.Tooltip.Tooltip.install(this.#newRegexInput, inputHelpText);
210222

211-
this.#newRegexInput.addEventListener('blur', this.#onNewRegexAdded.bind(this), false);
223+
this.#newRegexInput.addEventListener('blur', this.#addNewRegexToIgnoreList.bind(this), false);
212224
this.#newRegexInput.addEventListener('keydown', this.#handleKeyDown.bind(this), false);
213225
this.#newRegexInput.addEventListener('input', this.#handleInputChange.bind(this), false);
214226
this.#newRegexInput.addEventListener('focus', this.#startEditing.bind(this), false);

front_end/panels/timeline/overlays/components/EntryLabelOverlay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
import * as i18n from '../../../../core/i18n/i18n.js';
5+
import * as Platform from '../../../../core/platform/platform.js';
56
import * as ComponentHelpers from '../../../../ui/components/helpers/helpers.js';
67
import * as ThemeSupport from '../../../../ui/legacy/theme_support/theme_support.js';
78
import * as LitHtml from '../../../../ui/lit-html/lit-html.js';
@@ -150,7 +151,7 @@ export class EntryLabelOverlay extends HTMLElement {
150151
// We do not want to create multi-line labels.
151152
// Therefore, if the new key is `Enter` key, treat it
152153
// as the end of the label input and blur the input field.
153-
if (event.key === 'Enter' || event.key === 'Escape') {
154+
if (event.key === Platform.KeyboardUtilities.ENTER_KEY || event.key === Platform.KeyboardUtilities.ESCAPE_KEY) {
154155
// Note that we do not stop the event propagating here; this is on
155156
// purpose because we need it to bubble up into TimelineFlameChartView's
156157
// handler. That updates the state and deals with the keydown.

front_end/panels/timeline/overlays/components/TimeRangeOverlay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
import * as i18n from '../../../../core/i18n/i18n.js';
5+
import * as Platform from '../../../../core/platform/platform.js';
56
import type * as Trace from '../../../../models/trace/trace.js';
67
import * as LitHtml from '../../../../ui/lit-html/lit-html.js';
78
import * as VisualLogging from '../../../../ui/visual_logging/visual_logging.js';
@@ -236,7 +237,7 @@ export class TimeRangeOverlay extends HTMLElement {
236237
// as the end of the label input and blur the input field.
237238
// If the text field is empty when `Enter` or `Escape` are pressed,
238239
// dispatch an event to remove the time range.
239-
if (event.key === 'Enter' || event.key === 'Escape') {
240+
if (event.key === Platform.KeyboardUtilities.ENTER_KEY || event.key === Platform.KeyboardUtilities.ESCAPE_KEY) {
240241
// In DevTools, the `Escape` button will by default toggle the console
241242
// drawer, which we don't want here, so we need to call
242243
// `stopPropagation()`.

0 commit comments

Comments
 (0)