Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-9150: Run SIW when updating the glob fields. #9183

Merged
merged 3 commits into from
Mar 12, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { Widget, Message, BaseWidget, Key, StatefulWidget, MessageLoop } from '@theia/core/lib/browser';
import { Widget, Message, BaseWidget, Key, StatefulWidget, MessageLoop, KeyCode } from '@theia/core/lib/browser';
import { inject, injectable, postConstruct } from 'inversify';
import { SearchInWorkspaceResultTreeWidget } from './search-in-workspace-result-tree-widget';
import { SearchInWorkspaceOptions } from '../common/search-in-workspace-interface';
Expand Down Expand Up @@ -359,12 +359,24 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge
this.searchFieldContainerIsFocused = true;
this.update();
}
protected readonly unfocusSearchFieldContainer = () => this.doUnfocusSearchFieldContainer();
protected doUnfocusSearchFieldContainer(): void {

protected readonly blurSearchFieldContainer = () => this.doBlurSearchFieldContainer();
protected doBlurSearchFieldContainer(): void {
this.searchFieldContainerIsFocused = false;
this.update();
}

/**
* @deprecated use `blurSearchFieldContainer` instead.
*/
protected readonly unfocusSearchFieldContainer = this.blurSearchFieldContainer;
/**
* @deprecated use `doBlurSearchFieldContainer` instead.
*/
protected doUnfocusSearchFieldContainer(): void {
this.doBlurSearchFieldContainer();
}

protected readonly search = (e: React.KeyboardEvent) => {
e.persist();
const searchOnType = this.searchInWorkspacePreferences['search.searchOnType'];
Expand All @@ -375,7 +387,7 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge
};

protected readonly onKeyDownSearch = (e: React.KeyboardEvent) => {
if (e.keyCode === Key.ENTER.keyCode) {
if (Key.ENTER.keyCode === KeyCode.createKeyCode(e.nativeEvent).key?.keyCode) {
this.searchTerm = (e.target as HTMLInputElement).value;
this.resultTreeWidget.search(this.searchTerm, (this.searchInWorkspaceOptions || {}));
}
Expand All @@ -384,9 +396,9 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge
protected doSearch(e: React.KeyboardEvent): void {
if (e.target) {
const searchValue = (e.target as HTMLInputElement).value;
if (Key.ARROW_DOWN.keyCode === e.keyCode) {
if (Key.ARROW_DOWN.keyCode === KeyCode.createKeyCode(e.nativeEvent).key?.keyCode) {
this.resultTreeWidget.focusFirstResult();
} else if (this.searchTerm === searchValue && Key.ENTER.keyCode !== e.keyCode) {
} else if (this.searchTerm === searchValue && Key.ENTER.keyCode !== KeyCode.createKeyCode(e.nativeEvent).key?.keyCode) {
return;
} else {
this.searchTerm = searchValue;
Expand Down Expand Up @@ -415,7 +427,7 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge
const tooMany = this.searchInWorkspaceOptions.maxResults && this.resultNumber >= this.searchInWorkspaceOptions.maxResults ? 'tooManyResults' : '';
const className = `search-field-container ${tooMany} ${this.searchFieldContainerIsFocused ? 'focused' : ''}`;
return <div className={className}>
<div className='search-field' tabIndex={-1} onFocus={this.focusSearchFieldContainer} onBlur={this.unfocusSearchFieldContainer}>
<div className='search-field' tabIndex={-1} onFocus={this.focusSearchFieldContainer} onBlur={this.blurSearchFieldContainer}>
{input}
{optionContainer}
</div>
Expand Down Expand Up @@ -541,10 +553,27 @@ export class SearchInWorkspaceWidget extends BaseWidget implements StatefulWidge
id={kind + '-glob-field'}
onKeyUp={e => {
if (e.target) {
if (Key.ENTER.keyCode === e.keyCode) {
const targetValue = (e.target as HTMLInputElement).value || '';
let shouldSearch = Key.ENTER.keyCode === KeyCode.createKeyCode(e.nativeEvent).key?.keyCode;
const currentOptions = (this.searchInWorkspaceOptions[kind] || []).slice().map(s => s.trim()).sort();
const candidateOptions = this.splitOnComma(targetValue).map(s => s.trim()).sort();
const sameAs = (left: string[], right: string[]) => {
if (left.length !== right.length) {
return false;
}
for (let i = 0; i < left.length; i++) {
if (left[i] !== right[i]) {
return false;
}
}
return true;
};
if (!sameAs(currentOptions, candidateOptions)) {
this.searchInWorkspaceOptions[kind] = this.splitOnComma(targetValue);
shouldSearch = true;
}
if (shouldSearch) {
this.resultTreeWidget.search(this.searchTerm, this.searchInWorkspaceOptions);
} else {
this.searchInWorkspaceOptions[kind] = this.splitOnComma((e.target as HTMLInputElement).value);
}
}
}}
Expand Down