Handle focusing multiple composers

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-07-08 17:33:49 +02:00
parent 14687f3630
commit 7734f8aeef
No known key found for this signature in database
GPG key ID: 9760693FDD98A790
4 changed files with 33 additions and 3 deletions

View file

@ -832,6 +832,22 @@ export default class RoomView extends React.Component<IProps, IState> {
break; break;
} }
case Action.FocusAComposer: {
// re-dispatch to the correct composer
if (this.state.editState) {
dis.dispatch({
...payload,
action: Action.FocusEditMessageComposer,
});
} else {
dis.dispatch({
...payload,
action: Action.FocusComposer,
});
}
break;
}
case "scroll_to_bottom": case "scroll_to_bottom":
this.messagePanel?.jumpToLiveTimeline(); this.messagePanel?.jumpToLiveTimeline();
break; break;

View file

@ -94,7 +94,7 @@ class ReactionPicker extends React.Component<IProps, IState> {
this.props.mxEvent.getRoomId(), this.props.mxEvent.getRoomId(),
myReactions[reaction], myReactions[reaction],
); );
dis.dispatch({ action: Action.FocusComposer }); dis.dispatch({ action: Action.FocusAComposer });
// Tell the emoji picker not to bump this in the more frequently used list. // Tell the emoji picker not to bump this in the more frequently used list.
return false; return false;
} else { } else {
@ -106,7 +106,7 @@ class ReactionPicker extends React.Component<IProps, IState> {
}, },
}); });
dis.dispatch({ action: "message_sent" }); dis.dispatch({ action: "message_sent" });
dis.dispatch({ action: Action.FocusComposer }); dis.dispatch({ action: Action.FocusAComposer });
return true; return true;
} }
}; };

View file

@ -452,6 +452,8 @@ export default class EditMessageComposer extends React.Component<IProps, IState>
} else if (payload.text) { } else if (payload.text) {
this.editorRef.current?.insertPlaintext(payload.text); this.editorRef.current?.insertPlaintext(payload.text);
} }
} else if (payload.action === Action.FocusEditMessageComposer && this.editorRef.current) {
this.editorRef.current.focus();
} }
}; };

View file

@ -56,10 +56,22 @@ export enum Action {
CheckUpdates = "check_updates", CheckUpdates = "check_updates",
/** /**
* Focuses the user's cursor to the composer. No additional payload information required. * Focuses the user's cursor to the send message composer. No additional payload information required.
*/ */
FocusComposer = "focus_composer", FocusComposer = "focus_composer",
/**
* Focuses the user's cursor to the edit message composer. No additional payload information required.
*/
FocusEditMessageComposer = "focus_edit_message_composer",
/**
* Focuses the user's cursor to the edit message composer or send message
* composer based on the current edit state. No additional payload
* information required.
*/
FocusAComposer = "focus_a_composer",
/** /**
* Opens the user menu (previously known as the top left menu). No additional payload information required. * Opens the user menu (previously known as the top left menu). No additional payload information required.
*/ */