From b07dfb214b442aab00327423135f40e0d58e8e7e Mon Sep 17 00:00:00 2001
From: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sun, 28 Jul 2019 09:06:03 +0900
Subject: [PATCH] Added tab to indent

---
 desktop/sources/scripts/commander.js | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js
index 0ad259d..5a5f704 100644
--- a/desktop/sources/scripts/commander.js
+++ b/desktop/sources/scripts/commander.js
@@ -21,6 +21,11 @@ function Commander (ronin) {
     host.appendChild(this.el)
     this._input.addEventListener('input', this.onInput)
     this._input.addEventListener('click', this.onClick)
+
+    this._input.onkeydown = (e) => {
+      if (e.keyCode == 9 || e.which == 9) { e.preventDefault(); this.inject('  ') }
+    }
+
     this.docs.install()
   }
 
@@ -114,6 +119,11 @@ function Commander (ronin) {
     this.cache = this._input.value
   }
 
+  this.inject = function (injection, at = this._input.selectionStart) {
+    this._input.value = this._input.value.substring(0, this._input.selectionStart) + injection + this._input.value.substring(this._input.selectionEnd)
+    this._input.selectionEnd = at + injection.length
+  }
+
   this.injectPath = function (path) {
     if (this._input.value.indexOf('$') < 0) { return }
     this._input.value = this._input.value.replace('$path', `"${path}"`)