diff --git a/src/RichText.js b/src/RichText.js index 8cec5fb565..005465fc15 100644 --- a/src/RichText.js +++ b/src/RichText.js @@ -1,6 +1,10 @@ import {Editor, ContentState, convertFromHTML, DefaultDraftBlockRenderMap, DefaultDraftInlineStyle} from 'draft-js'; const ReactDOM = require('react-dom'); +const BLOCK_RENDER_MAP = DefaultDraftBlockRenderMap.set('unstyled', { + element: 'p' // draft uses
tags else you get 'orrible spacing - if (html.indexOf("
") === 0) { - html = html.substring("
".length); - } - if (html.lastIndexOf("
") === (html.length - "".length)) { - html = html.substring(0, html.length - "".length); - } - return html; -} - /* * The textInput part of the MessageComposer */ -module.exports = class extends React.Component { +export default class MessageComposerInput extends React.Component { constructor(props, context) { super(props, context); this.onAction = this.onAction.bind(this); @@ -75,7 +61,6 @@ module.exports = class extends React.Component { componentWillMount() { this.oldScrollHeight = 0; this.markdownEnabled = MARKDOWN_ENABLED; - var self = this; this.sentHistory = { // The list of typed messages. Index 0 is more recent data: [], @@ -150,21 +135,23 @@ module.exports = class extends React.Component { return true; }, - saveLastTextEntry: function() { + saveLastTextEntry: () => { // save the currently entered text in order to restore it later. // NB: This isn't 'originalText' because we want to restore // sent history items too! console.error('fixme'); - // window.sessionStorage.setItem("input_" + this.roomId, text); + const contentHTML = contentStateToHTML(this.state.editorState.getCurrentContent()); + window.sessionStorage.setItem("input_" + this.roomId, contentHTML); }, - setLastTextEntry: function() { + setLastTextEntry: () => { console.error('fixme'); - // var text = window.sessionStorage.getItem("input_" + this.roomId); - // if (text) { - // this.element.value = text; - // self.resizeInput(); - // } + const contentHTML = window.sessionStorage.getItem("input_" + this.roomId); + if (contentHTML) { + const content = HTMLtoContentState(contentHTML); + this.state.editorState = EditorState.createWithContent(content); + self.resizeInput(); + } } }; } @@ -172,12 +159,12 @@ module.exports = class extends React.Component { componentDidMount() { this.dispatcherRef = dis.register(this.onAction); this.sentHistory.init( - this.refs.textarea, + this.refs.editor, this.props.room.roomId ); this.resizeInput(); if (this.props.tabComplete) { - this.props.tabComplete.setTextArea(this.refs.textarea); + this.props.tabComplete.setTextArea(this.refs.editor); } } @@ -456,7 +443,7 @@ module.exports = class extends React.Component { const contentState = this.state.editorState.getCurrentContent(); if(!contentState.hasText()) - return false; + return true; const contentText = contentState.getPlainText(), contentHTML = contentStateToHTML(contentState); @@ -471,9 +458,16 @@ module.exports = class extends React.Component { } render() { + const containerStyle = { + overflow: 'auto' + }; + return ( -