Skip to content

Commit dfda8bb

Browse files
ktranDevtools-frontend LUCI CQ
authored andcommitted
[Quick open] Suggestion text is only set from outside
This changes the functionality of the suggestion text. The suggestion input is no longer set to be exactly like the input text on input. Instead, the suggestion text is only set from outside. If the suggestion text is not different from the input, there is no gain in showing anything anyway. This fixes a bug where we'd have overlapping suggestion & input texts if the input text was too long. In that case, the input text was scrolled to the end, while the suggestion text was not. Fixed: 405350055 Change-Id: I4933cb8f3c70790dd6885de744cc64369904b7b7 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6428565 Reviewed-by: Kateryna Prokopenko <[email protected]> Commit-Queue: Kim-Anh Tran <[email protected]>
1 parent 51544a7 commit dfda8bb

File tree

4 files changed

+6
-23
lines changed

4 files changed

+6
-23
lines changed

front_end/ui/components/text_prompt/TextPrompt.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,6 @@ describe('TextPrompt', () => {
6666
assert.lengthOf(textPromptInputs, 1);
6767
assert.strictEqual((textPromptInputs[0] as HTMLInputElement).value.trim(), 'text');
6868
});
69-
70-
it('sets the input and suggestion text correctly', () => {
71-
const component = renderTextPrompt(defaultTextPromptData);
72-
renderElementIntoDOM(component);
73-
74-
component.setText('@');
75-
component.setSuggestion('Command');
76-
77-
const textPromptInputs = component.shadowRoot!.querySelectorAll('.input');
78-
assert.strictEqual((textPromptInputs[0] as HTMLInputElement).value.trim(), '@');
79-
const textPromptSuggestions = component.shadowRoot!.querySelectorAll('.suggestion');
80-
assert.strictEqual((textPromptSuggestions[0] as HTMLInputElement).value.trim(), '@Command');
81-
});
8269
});
8370

8471
it('focus on the input element correctly', () => {

front_end/ui/components/text_prompt/TextPrompt.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ export class TextPrompt extends HTMLElement {
6161
this.setSelectedRange(this.#text().length, this.#text().length);
6262
}
6363

64-
onInput(): void {
65-
this.#suggestion().value = this.#text();
66-
this.dispatchEvent(new PromptInputEvent(this.#text()));
67-
}
68-
6964
onKeyDown(event: KeyboardEvent): void {
7065
if (event.key === Platform.KeyboardUtilities.ENTER_KEY) {
7166
event.preventDefault();
@@ -93,13 +88,12 @@ export class TextPrompt extends HTMLElement {
9388

9489
setSuggestion(suggestion: string): void {
9590
this.#suggestionText = suggestion;
96-
this.#suggestion().value += this.#suggestionText;
91+
this.#suggestion().value = this.#suggestionText;
9792
this.#render();
9893
}
9994

10095
setText(text: string): void {
10196
this.#input().value = text;
102-
this.#suggestion().value = this.#text();
10397

10498
if (this.#input().hasFocus()) {
10599
this.moveCaretToEndOfInput();
@@ -140,8 +134,9 @@ export class TextPrompt extends HTMLElement {
140134
<style>${textPromptStyles.cssText}</style>
141135
<span class="prefix">${this.#prefixText} </span>
142136
<span class="text-prompt-input"><input class="input" aria-label=${
143-
this.#ariaLabelText} spellcheck="false" @input=${this.onInput} @keydown=${
144-
this.onKeyDown}/><input class="suggestion" tabindex=-1 aria-label=${
137+
this.#ariaLabelText} spellcheck="false" @input=${
138+
() => this.dispatchEvent(new PromptInputEvent(
139+
this.#text()))} @keydown=${this.onKeyDown}/><input class="suggestion" tabindex=-1 aria-label=${
145140
this.#ariaLabelText + ' Suggestion'}></span>`;
146141
render(output, this.#shadow, {host: this});
147142
}

front_end/ui/legacy/components/quick_open/FilteredListWidget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ export class FilteredListWidget extends Common.ObjectWrapper.eventMixin<EventTyp
365365
}
366366
this.inputBoxElement.focus();
367367
this.inputBoxElement.setText(completion);
368+
this.inputBoxElement.setSuggestion('');
368369
this.setQuerySelectedRange(userEnteredText.length, completion.length);
369370
return true;
370371
}

front_end/ui/legacy/components/quick_open/QuickOpen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class QuickOpenImpl {
7373
const titlePrefixFunction = this.providers.get(prefix)?.titlePrefix;
7474
this.filteredListWidget.setCommandPrefix(titlePrefixFunction ? titlePrefixFunction() : '');
7575
const titleSuggestionFunction = (query === prefix) && this.providers.get(prefix)?.titleSuggestion;
76-
this.filteredListWidget.setCommandSuggestion(titleSuggestionFunction ? titleSuggestionFunction() : '');
76+
this.filteredListWidget.setCommandSuggestion(titleSuggestionFunction ? prefix + titleSuggestionFunction() : '');
7777

7878
if (this.prefix === prefix) {
7979
return;

0 commit comments

Comments
 (0)