mirror of https://github.com/vector-im/riot-web
Refactor shared code between `onUpArrow` and `onDownArrow`
parent
1523d304f2
commit
bcb67bb273
|
@ -556,36 +556,34 @@ export default class MessageComposerInput extends React.Component {
|
|||
this.autocomplete.hide();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
selectHistory = async (completion, delta) => {
|
||||
if (completion == null) {
|
||||
const newContent = this.historyManager.getItem(delta, this.state.isRichtextEnabled ? 'html' : 'markdown');
|
||||
if (!newContent) return false;
|
||||
let editorState = EditorState.push(
|
||||
this.state.editorState,
|
||||
newContent,
|
||||
'insert-characters',
|
||||
);
|
||||
|
||||
this.setState({editorState});
|
||||
return true;
|
||||
}
|
||||
return await this.setDisplayedCompletion(completion);
|
||||
};
|
||||
|
||||
onUpArrow = async (e) => {
|
||||
const completion = this.autocomplete.onUpArrow();
|
||||
if (completion == null && !(this.historyManager.currentIndex === -1 && this.state.editorState.getCurrentContent().hasText())) {
|
||||
const newContent = this.historyManager.getItem(-1, this.state.isRichtextEnabled ? 'html' : 'markdown');
|
||||
if (!newContent) return false;
|
||||
const editorState = EditorState.push(this.state.editorState,
|
||||
newContent,
|
||||
'insert-characters');
|
||||
this.setState({editorState});
|
||||
return true;
|
||||
}
|
||||
e.preventDefault();
|
||||
return await this.setDisplayedCompletion(completion);
|
||||
const completion = this.autocomplete.onUpArrow();
|
||||
return this.selectHistory(completion, -1);
|
||||
};
|
||||
|
||||
onDownArrow = async (e) => {
|
||||
const completion = this.autocomplete.onDownArrow();
|
||||
if (completion == null && !(this.historyManager.currentIndex === -1 && this.state.editorState.getCurrentContent().hasText())) {
|
||||
const newContent = this.historyManager.getItem(+1, this.state.isRichtextEnabled ? 'html' : 'markdown');
|
||||
if (!newContent) return false;
|
||||
const editorState = EditorState.push(this.state.editorState,
|
||||
newContent,
|
||||
'insert-characters');
|
||||
this.setState({editorState});
|
||||
return true;
|
||||
}
|
||||
e.preventDefault();
|
||||
return await this.setDisplayedCompletion(completion);
|
||||
const completion = this.autocomplete.onDownArrow();
|
||||
return this.selectHistory(completion, -1);
|
||||
};
|
||||
|
||||
// tab and shift-tab are mapped to down and up arrow respectively
|
||||
|
|
Loading…
Reference in New Issue