@@ -27,7 +27,7 @@ marked.setOptions({
27
27
smartypants : false
28
28
} ) ;
29
29
30
- import { Editor , EditorState , RichUtils } from 'draft-js' ;
30
+ import { Editor , EditorState , RichUtils , CompositeDecorator } from 'draft-js' ;
31
31
32
32
var MatrixClientPeg = require ( "../../../MatrixClientPeg" ) ;
33
33
var SlashCommands = require ( "../../../SlashCommands" ) ;
@@ -38,7 +38,7 @@ var sdk = require('../../../index');
38
38
var dis = require ( "../../../dispatcher" ) ;
39
39
var KeyCode = require ( "../../../KeyCode" ) ;
40
40
41
- import { contentStateToHTML , HTMLtoContentState } from '../../../RichText' ;
41
+ import { contentStateToHTML , HTMLtoContentState , getScopedDecorator } from '../../../RichText' ;
42
42
43
43
var TYPING_USER_TIMEOUT = 10000 ;
44
44
var TYPING_SERVER_TIMEOUT = 30000 ;
@@ -54,13 +54,14 @@ export default class MessageComposerInput extends React.Component {
54
54
this . onInputClick = this . onInputClick . bind ( this ) ;
55
55
56
56
this . state = {
57
- editorState : EditorState . createEmpty ( )
57
+ editorState : EditorState . createEmpty ( getScopedDecorator ( this . props ) )
58
58
} ;
59
59
}
60
60
61
61
componentWillMount ( ) {
62
62
this . oldScrollHeight = 0 ;
63
63
this . markdownEnabled = MARKDOWN_ENABLED ;
64
+ const component = this ;
64
65
this . sentHistory = {
65
66
// The list of typed messages. Index 0 is more recent
66
67
data : [ ] ,
@@ -73,7 +74,7 @@ export default class MessageComposerInput extends React.Component {
73
74
// The textarea element to set text to.
74
75
element : null ,
75
76
76
- init : function ( element , roomId ) {
77
+ init : function ( element , roomId ) {
77
78
this . roomId = roomId ;
78
79
this . element = element ;
79
80
this . position = - 1 ;
@@ -88,7 +89,7 @@ export default class MessageComposerInput extends React.Component {
88
89
}
89
90
} ,
90
91
91
- push : function ( text ) {
92
+ push : function ( text ) {
92
93
// store a message in the sent history
93
94
this . data . unshift ( text ) ;
94
95
window . sessionStorage . setItem (
@@ -101,7 +102,7 @@ export default class MessageComposerInput extends React.Component {
101
102
} ,
102
103
103
104
// move in the history. Returns true if we managed to move.
104
- next : function ( offset ) {
105
+ next : function ( offset ) {
105
106
if ( this . position === - 1 ) {
106
107
// user is going into the history, save the current line.
107
108
this . originalText = this . element . value ;
@@ -131,26 +132,26 @@ export default class MessageComposerInput extends React.Component {
131
132
this . element . value = this . originalText ;
132
133
}
133
134
134
- self . resizeInput ( ) ;
135
+ component . resizeInput ( ) ;
135
136
return true ;
136
137
} ,
137
138
138
- saveLastTextEntry : ( ) => {
139
+ saveLastTextEntry : function ( ) {
139
140
// save the currently entered text in order to restore it later.
140
141
// NB: This isn't 'originalText' because we want to restore
141
142
// sent history items too!
142
- console . error ( 'fixme' ) ;
143
- const contentHTML = contentStateToHTML ( this . state . editorState . getCurrentContent ( ) ) ;
143
+ const contentHTML = contentStateToHTML ( component . state . editorState . getCurrentContent ( ) ) ;
144
+ console . error ( contentHTML ) ;
144
145
window . sessionStorage . setItem ( "input_" + this . roomId , contentHTML ) ;
145
146
} ,
146
147
147
- setLastTextEntry : ( ) => {
148
- console . error ( 'fixme' ) ;
148
+ setLastTextEntry : function ( ) {
149
149
const contentHTML = window . sessionStorage . getItem ( "input_" + this . roomId ) ;
150
+ console . error ( contentHTML ) ;
150
151
if ( contentHTML ) {
151
152
const content = HTMLtoContentState ( contentHTML ) ;
152
- this . state . editorState = EditorState . createWithContent ( content ) ;
153
- self . resizeInput ( ) ;
153
+ component . setState ( { editorState : EditorState . createWithContent ( content , getScopedDecorator ( this . props ) ) } ) ;
154
+ component . resizeInput ( ) ;
154
155
}
155
156
}
156
157
} ;
@@ -177,10 +178,10 @@ export default class MessageComposerInput extends React.Component {
177
178
var editor = this . refs . editor ;
178
179
switch ( payload . action ) {
179
180
case 'focus_composer' :
180
- console . error ( 'fixme' ) ;
181
181
editor . focus ( ) ;
182
182
break ;
183
183
case 'insert_displayname' :
184
+ console . error ( 'fixme' ) ;
184
185
if ( textarea . value . length ) {
185
186
var left = textarea . value . substring ( 0 , textarea . selectionStart ) ;
186
187
var right = textarea . value . substring ( textarea . selectionEnd ) ;
@@ -426,6 +427,12 @@ export default class MessageComposerInput extends React.Component {
426
427
427
428
onChange ( editorState ) {
428
429
this . setState ( { editorState} ) ;
430
+
431
+ if ( editorState . getCurrentContent ( ) . hasText ( ) ) {
432
+ this . onTypingActivity ( )
433
+ } else {
434
+ this . onFinishedTyping ( ) ;
435
+ }
429
436
}
430
437
431
438
handleKeyCommand ( command ) {
@@ -451,7 +458,7 @@ export default class MessageComposerInput extends React.Component {
451
458
MatrixClientPeg . get ( ) . sendHtmlMessage ( this . props . room . roomId , contentText , contentHTML ) ;
452
459
453
460
this . setState ( {
454
- editorState : EditorState . createEmpty ( )
461
+ editorState : EditorState . createEmpty ( getScopedDecorator ( this . props ) )
455
462
} ) ;
456
463
457
464
return true ;
0 commit comments