Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2987 from matrix-org/bwindels/entertosendedit
Browse files Browse the repository at this point in the history
Message editing: shift+enter for newline, enter to send
  • Loading branch information
bwindels authored May 17, 2019
2 parents 0070540 + ca2e6d8 commit 396a06a
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/components/views/elements/MessageEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,44 @@ export default class MessageEditor extends React.Component {
}

_onKeyDown = (event) => {
if (event.metaKey || event.altKey || event.shiftKey) {
// insert newline on Shift+Enter
if (event.shiftKey && event.key === "Enter") {
event.preventDefault(); // just in case the browser does support this
document.execCommand("insertHTML", undefined, "\n");
return;
}
if (!this.model.autoComplete) {
// autocomplete or enter to send below shouldn't have any modifier keys pressed.
if (event.metaKey || event.altKey || event.shiftKey) {
return;
}
const autoComplete = this.model.autoComplete;
switch (event.key) {
case "Enter":
autoComplete.onEnter(event); break;
case "ArrowUp":
autoComplete.onUpArrow(event); break;
case "ArrowDown":
autoComplete.onDownArrow(event); break;
case "Tab":
autoComplete.onTab(event); break;
case "Escape":
autoComplete.onEscape(event); break;
default:
return; // don't preventDefault on anything else
if (this.model.autoComplete) {
const autoComplete = this.model.autoComplete;
switch (event.key) {
case "Enter":
autoComplete.onEnter(event); break;
case "ArrowUp":
autoComplete.onUpArrow(event); break;
case "ArrowDown":
autoComplete.onDownArrow(event); break;
case "Tab":
autoComplete.onTab(event); break;
case "Escape":
autoComplete.onEscape(event); break;
default:
return; // don't preventDefault on anything else
}
event.preventDefault();
} else if (event.key === "Enter") {
this._sendEdit();
event.preventDefault();
}
event.preventDefault();
}

_onCancelClicked = () => {
dis.dispatch({action: "edit_event", event: null});
}

_onSaveClicked = () => {
_sendEdit = () => {
const newContent = {
"msgtype": "m.text",
"body": textSerialize(this.model),
Expand Down Expand Up @@ -177,7 +186,7 @@ export default class MessageEditor extends React.Component {
></div>
<div className="mx_MessageEditor_buttons">
<AccessibleButton kind="secondary" onClick={this._onCancelClicked}>{_t("Cancel")}</AccessibleButton>
<AccessibleButton kind="primary" onClick={this._onSaveClicked}>{_t("Save")}</AccessibleButton>
<AccessibleButton kind="primary" onClick={this._sendEdit}>{_t("Save")}</AccessibleButton>
</div>
</div>;
}
Expand Down

0 comments on commit 396a06a

Please sign in to comment.