- { this.textInput('eventType', _t('Event Type')) }
- { this.state.isStateEvent && this.textInput('stateKey', _t('State Key')) }
+
+ { this.textInput('eventType', _t('Event Type')) }
+ { this.state.isStateEvent && this.textInput('stateKey', _t('State Key')) }
+
diff --git a/src/components/views/dialogs/ShareDialog.js b/src/components/views/dialogs/ShareDialog.js
index 13d8e99258..bd6746a1e5 100644
--- a/src/components/views/dialogs/ShareDialog.js
+++ b/src/components/views/dialogs/ShareDialog.js
@@ -114,7 +114,8 @@ export default class ShareDialog extends React.Component {
top: y,
message: successful ? _t('Copied!') : _t('Failed to copy'),
}, false);
- e.target.onmouseleave = close;
+ // Drop a reference to this close handler for componentWillUnmount
+ this.closeCopiedTooltip = e.target.onmouseleave = close;
}
onLinkSpecificEventCheckboxClick() {
@@ -131,6 +132,12 @@ export default class ShareDialog extends React.Component {
}
}
+ componentWillUnmount() {
+ // if the Copied tooltip is open then get rid of it, there are ways to close the modal which wouldn't close
+ // the tooltip otherwise, such as pressing Escape or clicking X really quickly
+ if (this.closeCopiedTooltip) this.closeCopiedTooltip();
+ }
+
render() {
let title;
let matrixToUrl;
diff --git a/src/components/views/elements/MemberEventListSummary.js b/src/components/views/elements/MemberEventListSummary.js
index 3c58f90a2b..dc9c72df6e 100644
--- a/src/components/views/elements/MemberEventListSummary.js
+++ b/src/components/views/elements/MemberEventListSummary.js
@@ -1,5 +1,6 @@
/*
Copyright 2016 OpenMarket Ltd
+Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -13,11 +14,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
+
import React from 'react';
import PropTypes from 'prop-types';
import sdk from '../../../index';
-const MemberAvatar = require('../avatars/MemberAvatar.js');
+import MemberAvatar from '../avatars/MemberAvatar';
import { _t } from '../../../languageHandler';
+import { formatCommaSeparatedList } from '../../../utils/FormattingUtils';
module.exports = React.createClass({
displayName: 'MemberEventListSummary',
@@ -105,7 +108,7 @@ module.exports = React.createClass({
);
});
- const desc = this._renderCommaSeparatedList(descs);
+ const desc = formatCommaSeparatedList(descs);
return _t('%(nameList)s %(transitionList)s', { nameList: nameList, transitionList: desc });
});
@@ -132,7 +135,7 @@ module.exports = React.createClass({
* included before "and [n] others".
*/
_renderNameList: function(users) {
- return this._renderCommaSeparatedList(users, this.props.summaryLength);
+ return formatCommaSeparatedList(users, this.props.summaryLength);
},
/**
@@ -283,35 +286,6 @@ module.exports = React.createClass({
return res;
},
- /**
- * Constructs a written English string representing `items`, with an optional limit on
- * the number of items included in the result. If specified and if the length of
- *`items` is greater than the limit, the string "and n others" will be appended onto
- * the result.
- * If `items` is empty, returns the empty string. If there is only one item, return
- * it.
- * @param {string[]} items the items to construct a string from.
- * @param {number?} itemLimit the number by which to limit the list.
- * @returns {string} a string constructed by joining `items` with a comma between each
- * item, but with the last item appended as " and [lastItem]".
- */
- _renderCommaSeparatedList(items, itemLimit) {
- const remaining = itemLimit === undefined ? 0 : Math.max(
- items.length - itemLimit, 0,
- );
- if (items.length === 0) {
- return "";
- } else if (items.length === 1) {
- return items[0];
- } else if (remaining > 0) {
- items = items.slice(0, itemLimit);
- return _t("%(items)s and %(count)s others", { items: items.join(', '), count: remaining } );
- } else {
- const lastItem = items.pop();
- return _t("%(items)s and %(lastItem)s", { items: items.join(', '), lastItem: lastItem });
- }
- },
-
_renderAvatars: function(roomMembers) {
const avatars = roomMembers.slice(0, this.props.avatarsMaxLength).map((m) => {
return (
diff --git a/src/components/views/elements/MessageEditor.js b/src/components/views/elements/MessageEditor.js
index b42923954b..0c249d067b 100644
--- a/src/components/views/elements/MessageEditor.js
+++ b/src/components/views/elements/MessageEditor.js
@@ -77,35 +77,46 @@ export default class MessageEditor extends React.Component {
}
_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) {
return;
}
- if (!this.model.autoComplete) {
- return;
+ 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();
+ } else if (event.key === "Escape") {
+ this._cancelEdit();
}
- 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();
}
- _onCancelClicked = () => {
+ _cancelEdit = () => {
dis.dispatch({action: "edit_event", event: null});
}
- _onSaveClicked = () => {
+ _sendEdit = () => {
const newContent = {
"msgtype": "m.text",
"body": textSerialize(this.model),
@@ -144,12 +155,7 @@ export default class MessageEditor extends React.Component {
componentDidMount() {
this._updateEditorState();
- const sel = document.getSelection();
- const range = document.createRange();
- range.selectNodeContents(this._editorRef);
- range.collapse(false);
- sel.removeAllRanges();
- sel.addRange(range);
+ setCaretPosition(this._editorRef, this.model, this.model.getPositionAtEnd());
this._editorRef.focus();
}
@@ -181,8 +187,8 @@ export default class MessageEditor extends React.Component {
ref={ref => this._editorRef = ref}
>
{_t(
+ "
reacted with %(shortName)s",
+ {
+ shortName,
+ },
+ {
+ reactors: () => {
+ return
+ {formatCommaSeparatedList(senders, 6)}
+
;
+ },
+ reactedWith: (sub) => {
+ return
+ {sub}
+
;
+ },
+ },
+ )}
;
+ }
+
+ let tooltip;
+ if (tooltipLabel) {
+ tooltip =