Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

ref.current.selectionStart

handleKeyDown(event) {
    if (event.keyCode === 9) { // tab was pressed
        event.preventDefault();
        var val = this.state.scriptString,
            start = event.target.selectionStart,
            end = event.target.selectionEnd;

        this.setState({"scriptString": val.substring(0, start) + '	' + val.substring(end)});
        // This line doesn't work. The caret position is always at the end of the line
        this.refs.input.selectionStart = this.refs.input.selectionEnd = start + 1;
    }
}
onScriptChange(event) {
   this.setState({scriptString: event.target.value});
}
render() {
    return (
        <textarea rows="30" cols="100" 
                  ref="input"
                  onKeyDown={this.handleKeyDown.bind(this)}
                  onChange={this.onScriptChange.bind(this)} 
                  value={this.state.scriptString}/>
    )
}
Comment

ref.current.selectionStart

handleKeyDown(event) {
      if (event.keyCode === 9) { // tab was pressed
          event.preventDefault();
          var val = this.state.scriptString,
          start = event.target.selectionStart,
          end = event.target.selectionEnd;
          this.setState(
              {
                  "scriptString": val.substring(0, start) + '	' + val.substring(end)
              },
              () => {
                  this.refs.input.selectionStart = this.refs.input.selectionEnd = start + 1
              });
      }
 }
Comment

PREVIOUS NEXT
Code Example
Javascript :: hex color js 
Javascript :: inappbrowser hide url 
Javascript :: the document object 
Javascript :: p cannot appear as a descendant of p react 
Javascript :: JavaScript Change the Value of Variables 
Javascript :: JavaScript for loop Display Numbers from 1 to 5 
Javascript :: react props class based static proptypes 
Javascript :: javascript Update Values of Properties 
Javascript :: javascript arrow function syntax 
Javascript :: javascript Set Subset Operation 
Javascript :: date methods javascript 
Javascript :: django debug toolbar javascript error 
Javascript :: error:0308010C:digital nextjs 
Javascript :: node js - excecute a child process and exchange message to and from 
Javascript :: javascript addall 
Javascript :: prevent js execution in elementor 
Javascript :: alternative for react-tilt 
Javascript :: phaser grid align 
Javascript :: phaser enable pixel art 
Javascript :: closre in js 
Javascript :: npm deploy next js with tailwind 
Javascript :: React "Nothing was returned from render Error" Solution 
Javascript :: how to get params from function js 
Javascript :: javascript array includes 
Javascript :: delete parent js 
Javascript :: module.exports equivalent typescript 
Javascript :: sequelize update 
Javascript :: SELECT * FROM USERSs 
Javascript :: return the first element in an array javascript 
Javascript :: var function js 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =