Reset the cursor

Once tab key is pressed, place the cursor 4 spaces away from
the location where the tab key was pressed.

This handles the case of when a tab key is pressed in the middle of
an existing note and the cursor was placed at the end of the document.

fix https://github.com/standardnotes/web/issues/50
This commit is contained in:
Lev Lazinskiy
2017-01-23 22:13:55 -08:00
parent dcf9291fce
commit 2908b5d5d7

View File

@@ -23,11 +23,17 @@ angular.module('app.frontend')
var handleTab = function (event) {
if (event.which == 9) {
event.preventDefault();
var start = event.target.selectionStart;
var end = event.target.selectionEnd;
var start = this.selectionStart;
var end = this.selectionEnd;
var spaces = " ";
event.target.value = event.target.value.substring(0, start)
+ spaces + event.target.value.substring(end);
// 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;
}
}