mirror of https://github.com/vector-im/riot-web
Message editing: shift+enter for newline, enter to send
parent
0070540b8a
commit
ca2e6d8eb2
|
@ -77,12 +77,17 @@ export default class MessageEditor extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onKeyDown = (event) => {
|
_onKeyDown = (event) => {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
// autocomplete or enter to send below shouldn't have any modifier keys pressed.
|
||||||
if (event.metaKey || event.altKey || event.shiftKey) {
|
if (event.metaKey || event.altKey || event.shiftKey) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.model.autoComplete) {
|
if (this.model.autoComplete) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
const autoComplete = this.model.autoComplete;
|
const autoComplete = this.model.autoComplete;
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "Enter":
|
case "Enter":
|
||||||
|
@ -99,13 +104,17 @@ export default class MessageEditor extends React.Component {
|
||||||
return; // don't preventDefault on anything else
|
return; // don't preventDefault on anything else
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
} else if (event.key === "Enter") {
|
||||||
|
this._sendEdit();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCancelClicked = () => {
|
_onCancelClicked = () => {
|
||||||
dis.dispatch({action: "edit_event", event: null});
|
dis.dispatch({action: "edit_event", event: null});
|
||||||
}
|
}
|
||||||
|
|
||||||
_onSaveClicked = () => {
|
_sendEdit = () => {
|
||||||
const newContent = {
|
const newContent = {
|
||||||
"msgtype": "m.text",
|
"msgtype": "m.text",
|
||||||
"body": textSerialize(this.model),
|
"body": textSerialize(this.model),
|
||||||
|
@ -177,7 +186,7 @@ export default class MessageEditor extends React.Component {
|
||||||
></div>
|
></div>
|
||||||
<div className="mx_MessageEditor_buttons">
|
<div className="mx_MessageEditor_buttons">
|
||||||
<AccessibleButton kind="secondary" onClick={this._onCancelClicked}>{_t("Cancel")}</AccessibleButton>
|
<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>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue