You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-20 16:22:28 +03:00
Merge onUpArrow and onDownArrow into more general moveSelection
This commit is contained in:
@@ -171,26 +171,13 @@ export default class Autocomplete extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// called from MessageComposerInput
|
// called from MessageComposerInput
|
||||||
onUpArrow(): ?Completion {
|
moveSelection(delta): ?Completion {
|
||||||
const completionCount = this.countCompletions();
|
const completionCount = this.countCompletions();
|
||||||
// completionCount + 1, since 0 means composer is selected
|
if (completionCount === 0) return; // there are no items to move the selection through
|
||||||
const selectionOffset = (completionCount + 1 + this.state.selectionOffset - 1)
|
|
||||||
% (completionCount + 1);
|
|
||||||
if (!completionCount) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
this.setSelection(selectionOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
// called from MessageComposerInput
|
// Note: selectionOffset 0 represents the unsubstituted text, while 1 means first pill selected
|
||||||
onDownArrow(): ?Completion {
|
const index = (this.state.selectionOffset + delta + completionCount + 1) % (completionCount + 1);
|
||||||
const completionCount = this.countCompletions();
|
this.setSelection(index);
|
||||||
// completionCount + 1, since 0 means composer is selected
|
|
||||||
const selectionOffset = (this.state.selectionOffset + 1) % (completionCount + 1);
|
|
||||||
if (!completionCount) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
this.setSelection(selectionOffset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onEscape(e): boolean {
|
onEscape(e): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user