mirror of https://github.com/vector-im/riot-web
Merge pull request #1237 from matrix-org/luke/fix-rte-colon-parity
Implement old composer feature that inserts ': ' or ' 'pull/21833/head
commit
199b771051
|
@ -55,6 +55,7 @@ export default class UserProvider extends AutocompleteProvider {
|
||||||
const displayName = (user.name || user.userId || '').replace(' (IRC)', ''); // FIXME when groups are done
|
const displayName = (user.name || user.userId || '').replace(' (IRC)', ''); // FIXME when groups are done
|
||||||
return {
|
return {
|
||||||
completion: displayName,
|
completion: displayName,
|
||||||
|
suffix: range.start === 0 ? ': ' : ' ',
|
||||||
entity: {
|
entity: {
|
||||||
type: 'LINK',
|
type: 'LINK',
|
||||||
mutability: 'IMMUTABLE',
|
mutability: 'IMMUTABLE',
|
||||||
|
|
|
@ -928,7 +928,7 @@ export default class MessageComposerInput extends React.Component {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {range = {}, completion = '', entity = null} = displayedCompletion;
|
const {range = {}, completion = '', entity = null, suffix = ''} = displayedCompletion;
|
||||||
let entityKey;
|
let entityKey;
|
||||||
if (entity) {
|
if (entity) {
|
||||||
entityKey = Entity.create(
|
entityKey = Entity.create(
|
||||||
|
@ -938,7 +938,7 @@ export default class MessageComposerInput extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentState = Modifier.replaceText(
|
let contentState = Modifier.replaceText(
|
||||||
activeEditorState.getCurrentContent(),
|
activeEditorState.getCurrentContent(),
|
||||||
RichText.textOffsetsToSelectionState(
|
RichText.textOffsetsToSelectionState(
|
||||||
range, activeEditorState.getCurrentContent().getBlocksAsArray(),
|
range, activeEditorState.getCurrentContent().getBlocksAsArray(),
|
||||||
|
@ -948,6 +948,12 @@ export default class MessageComposerInput extends React.Component {
|
||||||
entityKey,
|
entityKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Move the selection to the end of the block
|
||||||
|
const afterSelection = contentState.getSelectionAfter();
|
||||||
|
if (suffix) {
|
||||||
|
contentState = Modifier.replaceText(contentState, afterSelection, suffix);
|
||||||
|
}
|
||||||
|
|
||||||
let editorState = EditorState.push(activeEditorState, contentState, 'insert-characters');
|
let editorState = EditorState.push(activeEditorState, contentState, 'insert-characters');
|
||||||
editorState = EditorState.forceSelection(editorState, contentState.getSelectionAfter());
|
editorState = EditorState.forceSelection(editorState, contentState.getSelectionAfter());
|
||||||
this.setState({editorState, originalEditorState: activeEditorState});
|
this.setState({editorState, originalEditorState: activeEditorState});
|
||||||
|
|
Loading…
Reference in New Issue