mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-16 05:39:28 +00:00
Use eslint&prettier for code linting&formatting
This commit is contained in:
committed by
Francesco Stasi
parent
2a3873a923
commit
0592199858
@@ -8,47 +8,76 @@ import { SearchInWorkspaceWidget as TheiaSearchInWorkspaceWidget } from '@theia/
|
||||
*/
|
||||
@injectable()
|
||||
export class SearchInWorkspaceWidget extends TheiaSearchInWorkspaceWidget {
|
||||
|
||||
protected renderGlobField(kind: 'include' | 'exclude'): React.ReactNode {
|
||||
const currentValue = this.searchInWorkspaceOptions[kind];
|
||||
const value = currentValue && currentValue.join(', ') || '';
|
||||
return <div className='glob-field'>
|
||||
<div className='label'>{'files to ' + kind}</div>
|
||||
<input
|
||||
className='theia-input'
|
||||
type='text'
|
||||
size={1}
|
||||
defaultValue={value}
|
||||
id={kind + '-glob-field'}
|
||||
onKeyUp={e => {
|
||||
if (e.target) {
|
||||
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]) {
|
||||
const value = (currentValue && currentValue.join(', ')) || '';
|
||||
return (
|
||||
<div className="glob-field">
|
||||
<div className="label">{'files to ' + kind}</div>
|
||||
<input
|
||||
className="theia-input"
|
||||
type="text"
|
||||
size={1}
|
||||
defaultValue={value}
|
||||
id={kind + '-glob-field'}
|
||||
onKeyUp={(e) => {
|
||||
if (e.target) {
|
||||
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
|
||||
);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
if (!sameAs(currentOptions, candidateOptions)) {
|
||||
this.searchInWorkspaceOptions[kind] = this.splitOnComma(targetValue);
|
||||
shouldSearch = true;
|
||||
}
|
||||
if (shouldSearch) {
|
||||
this.resultTreeWidget.search(this.searchTerm, this.searchInWorkspaceOptions);
|
||||
}
|
||||
}}
|
||||
onFocus={
|
||||
kind === 'include'
|
||||
? this.handleFocusIncludesInputBox
|
||||
: this.handleFocusExcludesInputBox
|
||||
}
|
||||
}}
|
||||
onFocus={kind === 'include' ? this.handleFocusIncludesInputBox : this.handleFocusExcludesInputBox}
|
||||
onBlur={kind === 'include' ? this.handleBlurIncludesInputBox : this.handleBlurExcludesInputBox}></input>
|
||||
</div>;
|
||||
onBlur={
|
||||
kind === 'include'
|
||||
? this.handleBlurIncludesInputBox
|
||||
: this.handleBlurExcludesInputBox
|
||||
}
|
||||
></input>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user