@@ -28,7 +28,6 @@ marked.setOptions({
2828} ) ;
2929
3030import { Editor , EditorState , RichUtils } from 'draft-js' ;
31- import { stateToHTML } from 'draft-js-export-html' ;
3231
3332var MatrixClientPeg = require ( "../../../MatrixClientPeg" ) ;
3433var SlashCommands = require ( "../../../SlashCommands" ) ;
@@ -39,29 +38,16 @@ var sdk = require('../../../index');
3938var dis = require ( "../../../dispatcher" ) ;
4039var KeyCode = require ( "../../../KeyCode" ) ;
4140
42- import { contentStateToHTML } from '../../../RichText' ;
41+ import { contentStateToHTML , HTMLtoContentState } from '../../../RichText' ;
4342
4443var TYPING_USER_TIMEOUT = 10000 ;
4544var TYPING_SERVER_TIMEOUT = 30000 ;
4645var MARKDOWN_ENABLED = true ;
4746
48- function mdownToHtml ( mdown ) {
49- var html = marked ( mdown ) || "" ;
50- html = html . trim ( ) ;
51- // strip start and end <p> tags else you get 'orrible spacing
52- if ( html . indexOf ( "<p>" ) === 0 ) {
53- html = html . substring ( "<p>" . length ) ;
54- }
55- if ( html . lastIndexOf ( "</p>" ) === ( html . length - "</p>" . length ) ) {
56- html = html . substring ( 0 , html . length - "</p>" . length ) ;
57- }
58- return html ;
59- }
60-
6147/*
6248 * The textInput part of the MessageComposer
6349 */
64- module . exports = class extends React . Component {
50+ export default class MessageComposerInput extends React . Component {
6551 constructor ( props , context ) {
6652 super ( props , context ) ;
6753 this . onAction = this . onAction . bind ( this ) ;
@@ -75,7 +61,6 @@ module.exports = class extends React.Component {
7561 componentWillMount ( ) {
7662 this . oldScrollHeight = 0 ;
7763 this . markdownEnabled = MARKDOWN_ENABLED ;
78- var self = this ;
7964 this . sentHistory = {
8065 // The list of typed messages. Index 0 is more recent
8166 data : [ ] ,
@@ -150,34 +135,36 @@ module.exports = class extends React.Component {
150135 return true ;
151136 } ,
152137
153- saveLastTextEntry : function ( ) {
138+ saveLastTextEntry : ( ) => {
154139 // save the currently entered text in order to restore it later.
155140 // NB: This isn't 'originalText' because we want to restore
156141 // sent history items too!
157142 console . error ( 'fixme' ) ;
158- // window.sessionStorage.setItem("input_" + this.roomId, text);
143+ const contentHTML = contentStateToHTML ( this . state . editorState . getCurrentContent ( ) ) ;
144+ window . sessionStorage . setItem ( "input_" + this . roomId , contentHTML ) ;
159145 } ,
160146
161- setLastTextEntry : function ( ) {
147+ setLastTextEntry : ( ) => {
162148 console . error ( 'fixme' ) ;
163- // var text = window.sessionStorage.getItem("input_" + this.roomId);
164- // if (text) {
165- // this.element.value = text;
166- // self.resizeInput();
167- // }
149+ const contentHTML = window . sessionStorage . getItem ( "input_" + this . roomId ) ;
150+ if ( contentHTML ) {
151+ const content = HTMLtoContentState ( contentHTML ) ;
152+ this . state . editorState = EditorState . createWithContent ( content ) ;
153+ self . resizeInput ( ) ;
154+ }
168155 }
169156 } ;
170157 }
171158
172159 componentDidMount ( ) {
173160 this . dispatcherRef = dis . register ( this . onAction ) ;
174161 this . sentHistory . init (
175- this . refs . textarea ,
162+ this . refs . editor ,
176163 this . props . room . roomId
177164 ) ;
178165 this . resizeInput ( ) ;
179166 if ( this . props . tabComplete ) {
180- this . props . tabComplete . setTextArea ( this . refs . textarea ) ;
167+ this . props . tabComplete . setTextArea ( this . refs . editor ) ;
181168 }
182169 }
183170
@@ -456,7 +443,7 @@ module.exports = class extends React.Component {
456443
457444 const contentState = this . state . editorState . getCurrentContent ( ) ;
458445 if ( ! contentState . hasText ( ) )
459- return false ;
446+ return true ;
460447
461448 const contentText = contentState . getPlainText ( ) ,
462449 contentHTML = contentStateToHTML ( contentState ) ;
@@ -471,9 +458,16 @@ module.exports = class extends React.Component {
471458 }
472459
473460 render ( ) {
461+ const containerStyle = {
462+ overflow : 'auto'
463+ } ;
464+
474465 return (
475- < div className = "mx_MessageComposer_input" onClick = { this . onInputClick } style = { { overflow : 'auto' } } >
466+ < div className = "mx_MessageComposer_input"
467+ onClick = { this . onInputClick }
468+ style = { containerStyle } >
476469 < Editor ref = "editor"
470+ placeholder = "Type a message…"
477471 editorState = { this . state . editorState }
478472 onChange = { ( state ) => this . onChange ( state ) }
479473 handleKeyCommand = { ( command ) => this . handleKeyCommand ( command ) }
@@ -483,7 +477,7 @@ module.exports = class extends React.Component {
483477 }
484478} ;
485479
486- module . exports . propTypes = {
480+ MessageComposerInput . propTypes = {
487481 tabComplete : React . PropTypes . any ,
488482
489483 // a callback which is called when the height of the composer is
@@ -495,5 +489,4 @@ module.exports.propTypes = {
495489} ;
496490
497491// the height we limit the composer to
498- module . exports . MAX_HEIGHT = 100 ;
499-
492+ MessageComposerInput . MAX_HEIGHT = 100 ;
0 commit comments