diff --git a/app/assets/javascripts/app/frontend/controllers/editor.js b/app/assets/javascripts/app/frontend/controllers/editor.js index d822e089d..789f58a9c 100644 --- a/app/assets/javascripts/app/frontend/controllers/editor.js +++ b/app/assets/javascripts/app/frontend/controllers/editor.js @@ -516,17 +516,22 @@ angular.module('app.frontend') var handleTab = function (event) { if (!event.shiftKey && event.which == 9) { event.preventDefault(); - var start = this.selectionStart; - var end = this.selectionEnd; - var spaces = " "; - // Insert 4 spaces - this.value = this.value.substring(0, start) - + spaces + this.value.substring(end); + // Using document.execCommand gives us undo support + if(!document.execCommand("insertText", false, "\t")) { + // document.execCommand works great on Chrome/Safari but not Firefox + var start = this.selectionStart; + var end = this.selectionEnd; + var spaces = " "; - // Place cursor 4 spaces away from where - // the tab key was pressed - this.selectionStart = this.selectionEnd = start + 4; + // Insert 4 spaces + this.value = this.value.substring(0, start) + + spaces + this.value.substring(end); + + // Place cursor 4 spaces away from where + // the tab key was pressed + this.selectionStart = this.selectionEnd = start + 4; + } parent.note.text = this.value; parent.changesMade();