Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into t3chguy/i18n_analytics
This commit is contained in:
commit
4bdaa15c47
1 changed files with 32 additions and 7 deletions
|
@ -502,12 +502,18 @@ export default class MessageComposerInput extends React.Component {
|
||||||
// These are block types, not handled by RichUtils by default.
|
// These are block types, not handled by RichUtils by default.
|
||||||
const blockCommands = ['code-block', 'blockquote', 'unordered-list-item', 'ordered-list-item'];
|
const blockCommands = ['code-block', 'blockquote', 'unordered-list-item', 'ordered-list-item'];
|
||||||
const currentBlockType = RichUtils.getCurrentBlockType(this.state.editorState);
|
const currentBlockType = RichUtils.getCurrentBlockType(this.state.editorState);
|
||||||
|
|
||||||
|
const shouldToggleBlockFormat = (
|
||||||
|
command === 'backspace' ||
|
||||||
|
command === 'split-block'
|
||||||
|
) && currentBlockType !== 'unstyled';
|
||||||
|
|
||||||
if (blockCommands.includes(command)) {
|
if (blockCommands.includes(command)) {
|
||||||
newState = RichUtils.toggleBlockType(this.state.editorState, command);
|
newState = RichUtils.toggleBlockType(this.state.editorState, command);
|
||||||
} else if (command === 'strike') {
|
} else if (command === 'strike') {
|
||||||
// this is the only inline style not handled by Draft by default
|
// this is the only inline style not handled by Draft by default
|
||||||
newState = RichUtils.toggleInlineStyle(this.state.editorState, 'STRIKETHROUGH');
|
newState = RichUtils.toggleInlineStyle(this.state.editorState, 'STRIKETHROUGH');
|
||||||
} else if (command === 'backspace' && currentBlockType !== 'unstyled') {
|
} else if (shouldToggleBlockFormat) {
|
||||||
const currentStartOffset = this.state.editorState.getSelection().getStartOffset();
|
const currentStartOffset = this.state.editorState.getSelection().getStartOffset();
|
||||||
if (currentStartOffset === 0) {
|
if (currentStartOffset === 0) {
|
||||||
// Toggle current block type (setting it to 'unstyled')
|
// Toggle current block type (setting it to 'unstyled')
|
||||||
|
@ -718,9 +724,31 @@ export default class MessageComposerInput extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Use the original plaintext because `contextText` has had mentions stripped
|
// Use the original contentState because `contentText` has had mentions
|
||||||
// and these need to end up in contentHTML
|
// stripped and these need to end up in contentHTML.
|
||||||
const md = new Markdown(contentState.getPlainText());
|
|
||||||
|
// Replace all Entities of type `LINK` with markdown link equivalents.
|
||||||
|
// TODO: move this into `Markdown` and do the same conversion in the other
|
||||||
|
// two places (toggling from MD->RT mode and loading MD history into RT mode)
|
||||||
|
// but this can only be done when history includes Entities.
|
||||||
|
const pt = contentState.getBlocksAsArray().map((block) => {
|
||||||
|
let blockText = block.getText();
|
||||||
|
let offset = 0;
|
||||||
|
this.findLinkEntities(block, (start, end) => {
|
||||||
|
const entity = Entity.get(block.getEntityAt(start));
|
||||||
|
if (entity.getType() !== 'LINK') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const text = blockText.slice(offset + start, offset + end);
|
||||||
|
const url = entity.getData().url;
|
||||||
|
const mdLink = `[${text}](${url})`;
|
||||||
|
blockText = blockText.slice(0, offset + start) + mdLink + blockText.slice(offset + end);
|
||||||
|
offset += mdLink.length - text.length;
|
||||||
|
});
|
||||||
|
return blockText;
|
||||||
|
}).join('\n');
|
||||||
|
|
||||||
|
const md = new Markdown(pt);
|
||||||
if (md.isPlainText()) {
|
if (md.isPlainText()) {
|
||||||
contentText = md.toPlaintext();
|
contentText = md.toPlaintext();
|
||||||
} else {
|
} else {
|
||||||
|
@ -916,9 +944,6 @@ export default class MessageComposerInput extends React.Component {
|
||||||
url: href,
|
url: href,
|
||||||
isCompletion: true,
|
isCompletion: true,
|
||||||
});
|
});
|
||||||
if (!this.state.isRichtextEnabled) {
|
|
||||||
mdCompletion = `[${completion}](${href})`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let selection;
|
let selection;
|
||||||
|
|
Loading…
Reference in a new issue