mirror of
https://github.com/element-hq/element-web.git
synced 2024-11-30 23:31:28 +03:00
Merge pull request #1155 from matrix-org/luke/fix-rte-cursor-at-start-of-history
Fix issue where the cursor is put at the start of selected history item
This commit is contained in:
commit
d5585e29b1
1 changed files with 28 additions and 22 deletions
|
@ -556,36 +556,42 @@ export default class MessageComposerInput extends React.Component {
|
||||||
this.autocomplete.hide();
|
this.autocomplete.hide();
|
||||||
|
|
||||||
return true;
|
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',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Move selection to the end of the selected history
|
||||||
|
let newSelection = SelectionState.createEmpty(newContent.getLastBlock().getKey());
|
||||||
|
newSelection = newSelection.merge({
|
||||||
|
focusOffset: newContent.getLastBlock().getLength(),
|
||||||
|
anchorOffset: newContent.getLastBlock().getLength(),
|
||||||
|
});
|
||||||
|
editorState = EditorState.forceSelection(editorState, newSelection);
|
||||||
|
|
||||||
|
this.setState({editorState});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return await this.setDisplayedCompletion(completion);
|
||||||
};
|
};
|
||||||
|
|
||||||
onUpArrow = async (e) => {
|
onUpArrow = async (e) => {
|
||||||
const completion = this.autocomplete.onUpArrow();
|
|
||||||
if (completion == null) {
|
|
||||||
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();
|
e.preventDefault();
|
||||||
return await this.setDisplayedCompletion(completion);
|
const completion = this.autocomplete.onUpArrow();
|
||||||
|
return this.selectHistory(completion, -1);
|
||||||
};
|
};
|
||||||
|
|
||||||
onDownArrow = async (e) => {
|
onDownArrow = async (e) => {
|
||||||
const completion = this.autocomplete.onDownArrow();
|
|
||||||
if (completion == null) {
|
|
||||||
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();
|
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
|
// tab and shift-tab are mapped to down and up arrow respectively
|
||||||
|
|
Loading…
Reference in a new issue