delint and improve ts
This commit is contained in:
parent
ebfe38dc4a
commit
de88a39604
2 changed files with 15 additions and 15 deletions
|
@ -85,7 +85,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
this.applyNewProps();
|
this.applyNewProps();
|
||||||
}
|
}
|
||||||
|
|
||||||
private applyNewProps(oldQuery?: string, oldRoom?: Room) {
|
private applyNewProps(oldQuery?: string, oldRoom?: Room): void {
|
||||||
if (oldRoom && this.props.room.roomId !== oldRoom.roomId) {
|
if (oldRoom && this.props.room.roomId !== oldRoom.roomId) {
|
||||||
this.autocompleter.destroy();
|
this.autocompleter.destroy();
|
||||||
this.autocompleter = new Autocompleter(this.props.room);
|
this.autocompleter = new Autocompleter(this.props.room);
|
||||||
|
@ -103,7 +103,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
this.autocompleter.destroy();
|
this.autocompleter.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
complete(query: string, selection: ISelectionRange) {
|
private complete(query: string, selection: ISelectionRange): Promise<void> {
|
||||||
this.queryRequested = query;
|
this.queryRequested = query;
|
||||||
if (this.debounceCompletionsRequest) {
|
if (this.debounceCompletionsRequest) {
|
||||||
clearTimeout(this.debounceCompletionsRequest);
|
clearTimeout(this.debounceCompletionsRequest);
|
||||||
|
@ -134,7 +134,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
processQuery(query: string, selection: ISelectionRange) {
|
private processQuery(query: string, selection: ISelectionRange): Promise<void> {
|
||||||
return this.autocompleter.getCompletions(
|
return this.autocompleter.getCompletions(
|
||||||
query, selection, this.state.forceComplete, MAX_PROVIDER_MATCHES,
|
query, selection, this.state.forceComplete, MAX_PROVIDER_MATCHES,
|
||||||
).then((completions) => {
|
).then((completions) => {
|
||||||
|
@ -146,7 +146,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
processCompletions(completions: IProviderCompletions[]) {
|
private processCompletions(completions: IProviderCompletions[]): void {
|
||||||
const completionList = flatMap(completions, (provider) => provider.completions);
|
const completionList = flatMap(completions, (provider) => provider.completions);
|
||||||
|
|
||||||
// Reset selection when completion list becomes empty.
|
// Reset selection when completion list becomes empty.
|
||||||
|
@ -186,16 +186,16 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
hasSelection(): boolean {
|
public hasSelection(): boolean {
|
||||||
return this.countCompletions() > 0 && this.state.selectionOffset !== 0;
|
return this.countCompletions() > 0 && this.state.selectionOffset !== 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
countCompletions(): number {
|
public countCompletions(): number {
|
||||||
return this.state.completionList.length;
|
return this.state.completionList.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// called from MessageComposerInput
|
// called from MessageComposerInput
|
||||||
moveSelection(delta: number) {
|
public moveSelection(delta: number): void {
|
||||||
const completionCount = this.countCompletions();
|
const completionCount = this.countCompletions();
|
||||||
if (completionCount === 0) return; // there are no items to move the selection through
|
if (completionCount === 0) return; // there are no items to move the selection through
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
this.setSelection(1 + index);
|
this.setSelection(1 + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
onEscape(e: KeyboardEvent): boolean {
|
public onEscape(e: KeyboardEvent): boolean {
|
||||||
const completionCount = this.countCompletions();
|
const completionCount = this.countCompletions();
|
||||||
if (completionCount === 0) {
|
if (completionCount === 0) {
|
||||||
// autocomplete is already empty, so don't preventDefault
|
// autocomplete is already empty, so don't preventDefault
|
||||||
|
@ -217,7 +217,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
this.hide();
|
this.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
hide = () => {
|
private hide = (): void => {
|
||||||
this.setState({
|
this.setState({
|
||||||
hide: true,
|
hide: true,
|
||||||
selectionOffset: 1,
|
selectionOffset: 1,
|
||||||
|
@ -226,7 +226,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
forceComplete() {
|
public forceComplete(): Promise<number> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
forceComplete: true,
|
forceComplete: true,
|
||||||
|
@ -239,11 +239,11 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onConfirmCompletion = () => {
|
public onConfirmCompletion = (): void => {
|
||||||
this.onCompletionClicked(this.state.selectionOffset);
|
this.onCompletionClicked(this.state.selectionOffset);
|
||||||
}
|
};
|
||||||
|
|
||||||
onCompletionClicked = (selectionOffset: number): boolean => {
|
private onCompletionClicked = (selectionOffset: number): boolean => {
|
||||||
const count = this.countCompletions();
|
const count = this.countCompletions();
|
||||||
if (count === 0 || selectionOffset < 1 || selectionOffset > count) {
|
if (count === 0 || selectionOffset < 1 || selectionOffset > count) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -255,7 +255,7 @@ export default class Autocomplete extends React.PureComponent<IProps, IState> {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
setSelection(selectionOffset: number) {
|
private setSelection(selectionOffset: number): void {
|
||||||
this.setState({ selectionOffset, hide: false });
|
this.setState({ selectionOffset, hide: false });
|
||||||
if (this.props.onSelectionChange) {
|
if (this.props.onSelectionChange) {
|
||||||
this.props.onSelectionChange(selectionOffset - 1);
|
this.props.onSelectionChange(selectionOffset - 1);
|
||||||
|
|
|
@ -552,7 +552,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
|
||||||
model.autoComplete.close();
|
model.autoComplete.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.setState({showVisualBell: true});
|
this.setState({ showVisualBell: true });
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue