From 6c67ca1a0450fac873ec13d0137824a20aef8ebe Mon Sep 17 00:00:00 2001 From: Linus Lee Date: Thu, 24 Sep 2020 07:53:59 -0400 Subject: When hitting the tab key, actually indent in the editor. Also add boolean literal support --- static/js/main.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'static/js/main.js') 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 {
-- cgit v1.2.3-70-g09d2