diff options
author | Linus Lee <linus@thesephist.com> | 2020-09-24 07:53:59 -0400 |
---|---|---|
committer | Linus Lee <linus@thesephist.com> | 2020-09-24 07:53:59 -0400 |
commit | 6c67ca1a0450fac873ec13d0137824a20aef8ebe (patch) | |
tree | 1553d48f225c28475a8a39de7f9494323338077a /static/js/main.js | |
parent | a0163315d33cdaf902812782f20d92028440a1f1 (diff) | |
download | tabloid-fake-closure-6c67ca1a0450fac873ec13d0137824a20aef8ebe.tar.gz tabloid-fake-closure-6c67ca1a0450fac873ec13d0137824a20aef8ebe.zip |
When hitting the tab key, actually indent in the editor. Also add boolean literal support
Diffstat (limited to 'static/js/main.js')
-rw-r--r-- | static/js/main.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/static/js/main.js b/static/js/main.js index 7774bba..6dc22d3 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -50,6 +50,19 @@ class Editor extends Component { this.prog = evt.target.value; this.render(); } + this.handleKeydown = evt => { + if (evt.key === 'Tab') { + evt.preventDefault(); + const idx = evt.target.selectionStart; + if (idx !== null) { + const front = this.prog.substr(0, idx); + const back = this.prog.substr(idx); + this.prog = front + ' ' + back; + this.render(); + evt.target.setSelectionRange(idx + 4, idx + 4); + } + } + } } eval() { this.output = ''; @@ -85,7 +98,8 @@ class Editor extends Component { </div> <textarea class="editor-input" cols="30" rows="10" value=${this.prog} - oninput=${this.handleInput}> + oninput=${this.handleInput} + onkeydown=${this.handleKeydown}> </textarea> </div> <div class="output"> |