Tab insertion via document.execCommand

This commit is contained in:
Mo Bitar
2017-10-15 18:17:51 -05:00
parent cd42ef3132
commit 7e3a124112

View File

@@ -516,6 +516,10 @@ angular.module('app.frontend')
var handleTab = function (event) { var handleTab = function (event) {
if (!event.shiftKey && event.which == 9) { if (!event.shiftKey && event.which == 9) {
event.preventDefault(); event.preventDefault();
// 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 start = this.selectionStart;
var end = this.selectionEnd; var end = this.selectionEnd;
var spaces = " "; var spaces = " ";
@@ -527,6 +531,7 @@ angular.module('app.frontend')
// Place cursor 4 spaces away from where // Place cursor 4 spaces away from where
// the tab key was pressed // the tab key was pressed
this.selectionStart = this.selectionEnd = start + 4; this.selectionStart = this.selectionEnd = start + 4;
}
parent.note.text = this.value; parent.note.text = this.value;
parent.changesMade(); parent.changesMade();