Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove editor field for simpler textarea

  • Loading branch information...
commit 2ead738c6a51c58398c62e004f9c79b3e1bc4913 1 parent 503a3ec
@xadn authored
View
11 build/index.js
@@ -17407,7 +17407,8 @@ function defaultHtml(length) {
}
function prepareText(text, length) {
- return text.slice(0, length);
+ // return text.slice(0, length);
+ return text;
}
var Editor = React.createClass({displayName: 'Editor',
@@ -17428,7 +17429,11 @@ var Editor = React.createClass({displayName: 'Editor',
},
handleChange: function(e) {
- this.setState({text: prepareText(e.target.value, this.maxLength())});
+ var target = e.target;
+ this.setState({
+ text: prepareText(target.value, this.maxLength()),
+ selectionStart: target.selectionStart
+ });
},
render: function() {
@@ -17442,7 +17447,7 @@ var Editor = React.createClass({displayName: 'Editor',
return (
React.DOM.div( {className:"editor", style:style},
EditorBackground( {className:"editor-content", charWidth:this.props.charWidth, charHeight:this.props.charHeight, widthInChars:this.props.widthInChars, heightInChars:this.props.heightInChars} ),
- React.DOM.textarea( {className:"editor-content", value:this.state.text, onChange:this.handleChange} )
+ React.DOM.textarea( {ref:"ef", className:"editor-content", value:this.state.text, onChange:this.handleChange} )
)
);
}
View
5 package.json
@@ -4,9 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1",
- "start": "./node_modules/watchify/bin/cmd.js src/index.jsx -t reactify -o build/index.js",
- "build": "./node_modules/browserify/bin/cmd.js src/index.jsx -t reactify -o build/index.js"
+ "start": "watchify src/index.jsx -t reactify -o build/index.js",
+ "build": "browserify src/index.jsx -t reactify -o build/index.js"
},
"author": "",
"license": "ISC",
View
11 src/editor.js
@@ -10,7 +10,8 @@ function defaultHtml(length) {
}
function prepareText(text, length) {
- return text.slice(0, length);
+ // return text.slice(0, length);
+ return text;
}
var Editor = React.createClass({
@@ -31,7 +32,11 @@ var Editor = React.createClass({
},
handleChange: function(e) {
- this.setState({text: prepareText(e.target.value, this.maxLength())});
+ var target = e.target;
+ this.setState({
+ text: prepareText(target.value, this.maxLength()),
+ selectionStart: target.selectionStart
+ });
},
render: function() {
@@ -45,7 +50,7 @@ var Editor = React.createClass({
return (
<div className='editor' style={style}>
<EditorBackground className='editor-content' charWidth={this.props.charWidth} charHeight={this.props.charHeight} widthInChars={this.props.widthInChars} heightInChars={this.props.heightInChars} />
- <textarea className='editor-content' value={this.state.text} onChange={this.handleChange} />
+ <textarea ref='ef' className='editor-content' value={this.state.text} onChange={this.handleChange} />
</div>
);
}
View
39 src/editor_field.js
@@ -1,39 +0,0 @@
-/** @jsx React.DOM */
-var React = require('react');
-var ContentEditable = require('./content_editable');
-
-var ESCAPES = {
- '&': '&amp;',
- '<': '&lt;',
- '>': '&gt;',
- ' ': '&nbsp;'
-};
-
-function charEscape(c) {
- return ESCAPES[c] ? ESCAPES[c] : c;
-}
-
-function htmlEscape(html) {
- return [].map.call(html, charEscape).join('');
-}
-
-function noop() {}
-
-var EditorField = React.createClass({
- getDefaultProps: function() {
- return {value: '', onChange: noop};
- },
-
- handleChange: function(e) {
- var node = this.getDOMNode();
- this.props.onChange({target: {value: node.textContent}});
- },
-
- render: function() {
- return (
- <ContentEditable className={this.props.className} html={htmlEscape(this.props.value)} onChange={this.handleChange} />
- );
- }
-});
-
-module.exports = EditorField;
View
24 src/editor_field2.js
@@ -1,24 +0,0 @@
-/** @jsx React.DOM */
-var React = require('react');
-
-function noop() {}
-
-var EditorField = React.createClass({
- getDefaultProps: function() {
- return {value: '', onChange: noop};
- },
-
- handleChange: function(e) {
- console.log('change', e.target.value.length)
- this.props.onChange({target: {value: e.target.value}});
- },
-
- render: function() {
- console.log('value', this.props.value.length)
- return (
-
- );
- }
-});
-
-module.exports = EditorField;
Please sign in to comment.
Something went wrong with that request. Please try again.