From c17830883d7188bb021783d71e7df7e803522b92 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 18 Aug 2016 19:38:40 +0000
Subject: [PATCH] Allow the entry of tab characters into the edit page
 textarea. Fixes #84.

---
 build/index.php          | 15 +++++++++++++++
 module_index.json        |  4 ++--
 modules/page-credits.php |  5 +++++
 modules/page-edit.php    | 10 ++++++++++
 4 files changed, 32 insertions(+), 2 deletions(-)
 mode change 100644 => 100755 modules/page-credits.php

diff --git a/build/index.php b/build/index.php
index c3bda80..afed82a 100755
--- a/build/index.php
+++ b/build/index.php
@@ -3237,6 +3237,11 @@ register_module([
 					"thing_url" => "https://gist.github.com/jbroadway/2836900",
 					"icon" => "https://avatars2.githubusercontent.com/u/87886?v=3&s=24"
 				],
+				"Insert tab characters into textareas" => [
+					"author" => "Unknown",
+					"author_url" => "http://stackoverflow.com/q/6140632/1460422",
+					"thing_url" => "https://jsfiddle.net/2wAzx/13/",
+				],
 				"Default Favicon" => [
 					"author" => "bluefrog23",
 					"author_url" => "https://openclipart.org/user-detail/bluefrog23/",
@@ -3583,6 +3588,16 @@ register_module([
 			<input type='text' name='tags' value='$page_tags' placeholder='Enter some tags for the page here. Separate them with commas.' title='Enter some tags for the page here. Separate them with commas.' tabindex='2' />
 			<p class='editing-message'>$settings->editing_message</p>
 			<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
+			<script>
+				// Adapted from https://jsfiddle.net/2wAzx/13/
+				document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event) => {
+					var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
+					event.target.value = currentValue.substring(0, startPos) + \"\\t\" + currentValue.substring(endPos);
+					event.target.selectionStart = event.target.selectionEnd = startPos + 1;
+					event.stopPropagation(); event.preventDefault();
+					return false;
+				});
+			</script>
 		</form>";
 			exit(page_renderer::render_main("$title - $settings->sitename", $content));
 		});
diff --git a/module_index.json b/module_index.json
index 01b87e4..721f6cc 100755
--- a/module_index.json
+++ b/module_index.json
@@ -86,7 +86,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds the credits page. You *must* have this module :D",
         "id": "page-credits",
-        "lastupdate": 1465815023,
+        "lastupdate": 1471548456,
         "optional": false
     },
     {
@@ -113,7 +113,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
         "id": "page-edit",
-        "lastupdate": 1471525437,
+        "lastupdate": 1471548511,
         "optional": false
     },
     {
diff --git a/modules/page-credits.php b/modules/page-credits.php
old mode 100644
new mode 100755
index 9f78b68..e722931
--- a/modules/page-credits.php
+++ b/modules/page-credits.php
@@ -53,6 +53,11 @@ register_module([
 					"thing_url" => "https://gist.github.com/jbroadway/2836900",
 					"icon" => "https://avatars2.githubusercontent.com/u/87886?v=3&s=24"
 				],
+				"Insert tab characters into textareas" => [
+					"author" => "Unknown",
+					"author_url" => "http://stackoverflow.com/q/6140632/1460422",
+					"thing_url" => "https://jsfiddle.net/2wAzx/13/",
+				],
 				"Default Favicon" => [
 					"author" => "bluefrog23",
 					"author_url" => "https://openclipart.org/user-detail/bluefrog23/",
diff --git a/modules/page-edit.php b/modules/page-edit.php
index e964427..83ed01f 100755
--- a/modules/page-edit.php
+++ b/modules/page-edit.php
@@ -87,6 +87,16 @@ register_module([
 			<input type='text' name='tags' value='$page_tags' placeholder='Enter some tags for the page here. Separate them with commas.' title='Enter some tags for the page here. Separate them with commas.' tabindex='2' />
 			<p class='editing-message'>$settings->editing_message</p>
 			<input name='submit-edit' type='submit' value='Save Page' tabindex='3' />
+			<script>
+				// Adapted from https://jsfiddle.net/2wAzx/13/
+				document.querySelector(\"[name=content]\").addEventListener(\"keydown\", (event) => {
+					var currentValue = event.target.value, startPos = event.target.selectionStart, endPos = event.target.selectionEnd;
+					event.target.value = currentValue.substring(0, startPos) + \"\\t\" + currentValue.substring(endPos);
+					event.target.selectionStart = event.target.selectionEnd = startPos + 1;
+					event.stopPropagation(); event.preventDefault();
+					return false;
+				});
+			</script>
 		</form>";
 			exit(page_renderer::render_main("$title - $settings->sitename", $content));
 		});
