refocus editor immediately after executing commands
and persist selections correctly across blur/focus
This commit is contained in:
parent
e7a4ffaf45
commit
794a60b9f8
1 changed files with 16 additions and 1 deletions
|
@ -1005,12 +1005,13 @@ export default class MessageComposerInput extends React.Component {
|
||||||
this.historyManager.save(editorState, this.state.isRichTextEnabled ? 'rich' : 'markdown');
|
this.historyManager.save(editorState, this.state.isRichTextEnabled ? 'rich' : 'markdown');
|
||||||
this.setState({
|
this.setState({
|
||||||
editorState: this.createEditorState(),
|
editorState: this.createEditorState(),
|
||||||
|
}, ()=>{
|
||||||
|
this.refs.editor.focus();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (cmd.promise) {
|
if (cmd.promise) {
|
||||||
cmd.promise.then(()=>{
|
cmd.promise.then(()=>{
|
||||||
console.log("Command success.");
|
console.log("Command success.");
|
||||||
this.refs.editor.focus();
|
|
||||||
}, (err)=>{
|
}, (err)=>{
|
||||||
console.error("Command failure: %s", err);
|
console.error("Command failure: %s", err);
|
||||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||||
|
@ -1499,6 +1500,18 @@ export default class MessageComposerInput extends React.Component {
|
||||||
this.handleKeyCommand('toggle-mode');
|
this.handleKeyCommand('toggle-mode');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onBlur = (e) => {
|
||||||
|
this.selection = this.state.editorState.selection;
|
||||||
|
};
|
||||||
|
|
||||||
|
onFocus = (e) => {
|
||||||
|
if (this.selection) {
|
||||||
|
const change = this.state.editorState.change().select(this.selection);
|
||||||
|
this.onChange(change);
|
||||||
|
delete this.selection;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const activeEditorState = this.state.originalEditorState || this.state.editorState;
|
const activeEditorState = this.state.originalEditorState || this.state.editorState;
|
||||||
|
|
||||||
|
@ -1532,6 +1545,8 @@ export default class MessageComposerInput extends React.Component {
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
onKeyDown={this.onKeyDown}
|
onKeyDown={this.onKeyDown}
|
||||||
onPaste={this.onPaste}
|
onPaste={this.onPaste}
|
||||||
|
onBlur={this.onBlur}
|
||||||
|
onFocus={this.onFocus}
|
||||||
renderNode={this.renderNode}
|
renderNode={this.renderNode}
|
||||||
renderMark={this.renderMark}
|
renderMark={this.renderMark}
|
||||||
spellCheck={true}
|
spellCheck={true}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue