Tab insertion via document.execCommand
This commit is contained in:
@@ -516,17 +516,22 @@ 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();
|
||||||
var start = this.selectionStart;
|
|
||||||
var end = this.selectionEnd;
|
|
||||||
var spaces = " ";
|
|
||||||
|
|
||||||
// Insert 4 spaces
|
// Using document.execCommand gives us undo support
|
||||||
this.value = this.value.substring(0, start)
|
if(!document.execCommand("insertText", false, "\t")) {
|
||||||
+ spaces + this.value.substring(end);
|
// 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
|
// Insert 4 spaces
|
||||||
// the tab key was pressed
|
this.value = this.value.substring(0, start)
|
||||||
this.selectionStart = this.selectionEnd = start + 4;
|
+ 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.note.text = this.value;
|
||||||
parent.changesMade();
|
parent.changesMade();
|
||||||
|
|||||||
Reference in New Issue
Block a user