@@ -165,17 +165,18 @@ export default class MessageComposerInput extends React.Component {
165
165
this . client = MatrixClientPeg . get ( ) ;
166
166
}
167
167
168
- findLinkEntities ( contentBlock , callback ) {
168
+ findLinkEntities ( contentState : ContentState , contentBlock : ContentBlock , callback ) {
169
169
contentBlock . findEntityRanges (
170
170
( character ) => {
171
171
const entityKey = character . getEntity ( ) ;
172
172
return (
173
173
entityKey !== null &&
174
- Entity . get ( entityKey ) . getType ( ) === 'LINK'
174
+ contentState . getEntity ( entityKey ) . getType ( ) === 'LINK'
175
175
) ;
176
176
} , callback ,
177
177
) ;
178
178
}
179
+
179
180
/*
180
181
* "Does the right thing" to create an EditorState, based on:
181
182
* - whether we've got rich text mode enabled
@@ -188,7 +189,7 @@ export default class MessageComposerInput extends React.Component {
188
189
strategy : this . findLinkEntities . bind ( this ) ,
189
190
component : ( entityProps ) => {
190
191
const Pill = sdk . getComponent ( 'elements.Pill' ) ;
191
- const { url} = Entity . get ( entityProps . entityKey ) . getData ( ) ;
192
+ const { url} = entityProps . contentState . getEntity ( entityProps . entityKey ) . getData ( ) ;
192
193
if ( Pill . isPillUrl ( url ) ) {
193
194
return < Pill url = { url } room = { this . props . room } offsetKey = { entityProps . offsetKey } /> ;
194
195
}
@@ -713,7 +714,7 @@ export default class MessageComposerInput extends React.Component {
713
714
const hasLink = blocks . some ( ( block ) => {
714
715
return block . getCharacterList ( ) . filter ( ( c ) => {
715
716
const entityKey = c . getEntity ( ) ;
716
- return entityKey && Entity . get ( entityKey ) . getType ( ) === 'LINK' ;
717
+ return entityKey && contentState . getEntity ( entityKey ) . getType ( ) === 'LINK' ;
717
718
} ) . size > 0 ;
718
719
} ) ;
719
720
shouldSendHTML = hasLink ;
@@ -734,8 +735,8 @@ export default class MessageComposerInput extends React.Component {
734
735
const pt = contentState . getBlocksAsArray ( ) . map ( ( block ) => {
735
736
let blockText = block . getText ( ) ;
736
737
let offset = 0 ;
737
- this . findLinkEntities ( block , ( start , end ) => {
738
- const entity = Entity . get ( block . getEntityAt ( start ) ) ;
738
+ this . findLinkEntities ( contentState , block , ( start , end ) => {
739
+ const entity = contentState . getEntity ( block . getEntityAt ( start ) ) ;
739
740
if ( entity . getType ( ) !== 'LINK' ) {
740
741
return ;
741
742
}
@@ -936,32 +937,27 @@ export default class MessageComposerInput extends React.Component {
936
937
}
937
938
938
939
const { range = null , completion = '' , href = null , suffix = '' } = displayedCompletion ;
940
+ let contentState = activeEditorState . getCurrentContent ( ) ;
939
941
940
942
let entityKey ;
941
- let mdCompletion ;
942
943
if ( href ) {
943
- entityKey = Entity . create ( 'LINK' , 'IMMUTABLE' , {
944
+ contentState = contentState . createEntity ( 'LINK' , 'IMMUTABLE' , {
944
945
url : href ,
945
946
isCompletion : true ,
946
947
} ) ;
948
+ entityKey = contentState . getLastCreatedEntityKey ( ) ;
947
949
}
948
950
949
951
let selection ;
950
952
if ( range ) {
951
953
selection = RichText . textOffsetsToSelectionState (
952
- range , activeEditorState . getCurrentContent ( ) . getBlocksAsArray ( ) ,
954
+ range , contentState . getBlocksAsArray ( ) ,
953
955
) ;
954
956
} else {
955
957
selection = activeEditorState . getSelection ( ) ;
956
958
}
957
959
958
- let contentState = Modifier . replaceText (
959
- activeEditorState . getCurrentContent ( ) ,
960
- selection ,
961
- mdCompletion || completion ,
962
- null ,
963
- entityKey ,
964
- ) ;
960
+ contentState = Modifier . replaceText ( contentState , selection , completion , null , entityKey ) ;
965
961
966
962
// Move the selection to the end of the block
967
963
const afterSelection = contentState . getSelectionAfter ( ) ;
@@ -1047,7 +1043,7 @@ export default class MessageComposerInput extends React.Component {
1047
1043
offset -= sum ;
1048
1044
1049
1045
const entityKey = block . getEntityAt ( offset ) ;
1050
- const entity = entityKey ? Entity . get ( entityKey ) : null ;
1046
+ const entity = entityKey ? contentState . getEntity ( entityKey ) : null ;
1051
1047
if ( entity && entity . getData ( ) . isCompletion ) {
1052
1048
// This is a completed mention, so do not insert MD link, just text
1053
1049
return text ;
0 commit comments