diff --git a/src/components/views/elements/Pill.js b/src/components/views/elements/Pill.js index 39987228e5..89607f4eb8 100644 --- a/src/components/views/elements/Pill.js +++ b/src/components/views/elements/Pill.js @@ -92,7 +92,6 @@ export default React.createClass({ avatar = ; } } - const classes = classNames({ "mx_UserPill": isUserPill, "mx_RoomPill": isRoomPill, diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 10414ecbeb..2863b13243 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -731,10 +731,33 @@ export default class MessageComposerInput extends React.Component { sendTextFn = this.client.sendEmoteMessage; } - // Strip MD user mentions to preserve plaintext mention behaviour + // Strip MD user (tab-completed) mentions to preserve plaintext mention behaviour contentText = contentText.replace(REGEX_MATRIXTO_MARKDOWN_GLOBAL, - (markdownLink, text, resource, prefix) => { - return prefix === '@' ? text : markdownLink; + (markdownLink, text, resource, prefix, offset) => { + // Calculate the offset relative to the current block that the offset is in + let sum = 0; + const blocks = contentState.getBlocksAsArray(); + let block; + for (let i = 0; i < blocks.length; i++) { + block = blocks[i]; + sum += block.getLength(); + if (sum > offset) { + sum -= block.getLength(); + break; + } + } + offset -= sum; + + const entityKey = block.getEntityAt(offset); + const entity = entityKey ? Entity.get(entityKey) : null; + if (entity && entity.getData().isCompletion && prefix === '@') { + // This is a completed mention, so do not insert MD link, just text + return text; + } else { + // This is either a MD link that was typed into the composer or another + // type of pill (e.g. room pill) + return markdownLink; + } }); let sendMessagePromise; @@ -900,7 +923,10 @@ export default class MessageComposerInput extends React.Component { let entityKey; let mdCompletion; if (href) { - entityKey = Entity.create('LINK', 'IMMUTABLE', {url: href}); + entityKey = Entity.create('LINK', 'IMMUTABLE', { + url: href, + isCompletion: true, + }); if (!this.state.isRichtextEnabled) { mdCompletion = `[${completion}](${href})`; }