@@ -387,17 +387,28 @@ export default class MessageComposerInput extends React.Component {
387
387
const anchorText = editorState . anchorText ;
388
388
if ( ( ! anchorText || anchorText . text === '' ) && editorState . anchorBlock . nodes . size === 1 ) {
389
389
// replace the current block rather than split the block
390
+ // XXX: this destroys our focus by deleting the thing we are anchored/focused on
390
391
change = change . replaceNodeByKey ( editorState . anchorBlock . key , quote ) ;
391
- }
392
- else {
392
+ } else {
393
393
// insert it into the middle of the block (splitting it)
394
394
change = change . insertBlock ( quote ) ;
395
395
}
396
- change = change . insertFragmentByKey ( quote . key , 0 , fragment . document )
397
- . focus ( ) ;
396
+
397
+ // XXX: heuristic to strip out wrapping <p> which breaks quoting in RT mode
398
+ if ( fragment . document . nodes . size && fragment . document . nodes . get ( 0 ) . type === DEFAULT_NODE ) {
399
+ change = change . insertFragmentByKey ( quote . key , 0 , fragment . document . nodes . get ( 0 ) ) ;
400
+ } else {
401
+ change = change . insertFragmentByKey ( quote . key , 0 , fragment . document ) ;
402
+ }
403
+
404
+ // XXX: this is to bring back the focus in a sane place and add a paragraph after it
405
+ change = change . select ( {
406
+ anchorKey : quote . key ,
407
+ focusKey : quote . key ,
408
+ } ) . collapseToEndOfBlock ( ) . insertBlock ( Block . create ( DEFAULT_NODE ) ) . focus ( ) ;
409
+
398
410
this . onChange ( change ) ;
399
- }
400
- else {
411
+ } else {
401
412
let fragmentChange = fragment . change ( ) ;
402
413
fragmentChange . moveToRangeOf ( fragment . document )
403
414
. wrapBlock ( quote ) ;
@@ -1301,6 +1312,14 @@ export default class MessageComposerInput extends React.Component {
1301
1312
await this . setDisplayedCompletion ( null ) ; // restore originalEditorState
1302
1313
} ;
1303
1314
1315
+ onAutocompleteConfirm = ( displayedCompletion : ?Completion ) => {
1316
+ this . focusComposer ( ) ;
1317
+ // XXX: this fails if the composer isn't focused so focus it and delay the completion until next tick
1318
+ setImmediate ( ( ) => {
1319
+ this . setDisplayedCompletion ( displayedCompletion ) ;
1320
+ } ) ;
1321
+ } ;
1322
+
1304
1323
/* If passed null, restores the original editor content from state.originalEditorState.
1305
1324
* If passed a non-null displayedCompletion, modifies state.originalEditorState to compute new state.editorState.
1306
1325
*/
@@ -1563,7 +1582,7 @@ export default class MessageComposerInput extends React.Component {
1563
1582
< Autocomplete
1564
1583
ref = { ( e ) => this . autocomplete = e }
1565
1584
room = { this . props . room }
1566
- onConfirm = { this . setDisplayedCompletion }
1585
+ onConfirm = { this . onAutocompleteConfirm }
1567
1586
onSelectionChange = { this . setDisplayedCompletion }
1568
1587
query = { this . suppressAutoComplete ? '' : this . getAutocompleteQuery ( activeEditorState ) }
1569
1588
selection = { this . getSelectionRange ( activeEditorState ) }
0 commit comments