From 13874b910843c4d45cf5b7930bcefa234eb7ddae Mon Sep 17 00:00:00 2001 From: Jackson de Campos Date: Sun, 6 Jul 2014 12:14:37 -0700 Subject: [PATCH] Add tab indentation --- index.html | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index bb41830..0a62583 100644 --- a/index.html +++ b/index.html @@ -284,20 +284,43 @@ function restore_text() { if (typeof localStorage != "undefined") $("#writearea").attr("value", localStorage.text).keyup(); } + +function tabs(e) { + if(e.keyCode === 9) { // if tab + var el = e.target; + + // get caret position or selection + var start = el.selectionStart; + var end = el.selectionEnd; + + var value = el.value; + + // set text to: text before caret + tab + text after caret + el.valuse = value.substring(0, start + + "\t" + + value.substring(end)); + + // reset caret position + el.selectionStart = el.selectionEnd = start + 1; + + // keep focus + e.preventDefault(); + } +} - +

Written? Kitten!

@@ -305,7 +328,7 @@

Warning!

Hey!

Looks like your browser supports local storage. That's great! Your writing will be saved even if you close this page.

-

We can't take responsibility for things going wrong, though, so you might want to +

We can't take responsibility for things going wrong, though, so you might want to copy and paste your work to an external document every so often, just in case.

@@ -314,7 +337,7 @@

Hey!

- +