|
@@ -203,27 +203,19 @@ Formatter.prototype._processKey = function (chars, delKey) { |
|
|
this.delta = (-1) * Math.abs(this.sel.begin - this.sel.end);
|
|
|
this.val = utils.removeChars(this.val, this.sel.begin, this.sel.end);
|
|
|
}
|
|
|
- // If delKey
|
|
|
- else if (delKey) {
|
|
|
- // Delete
|
|
|
- if (delKey && delKey == 46) {
|
|
|
- // Adjust focus to make sure its not on a formatted char
|
|
|
- while (this.chars[this.sel.begin]) {
|
|
|
- this._nextPos();
|
|
|
- }
|
|
|
- // As long as we are not at the end
|
|
|
- if (this.sel.begin < this.val.length) {
|
|
|
- // We will simulate a delete by moving the caret to the next char
|
|
|
- // and then deleting
|
|
|
- this._nextPos();
|
|
|
- this.val = utils.removeChars(this.val, this.sel.end -1, this.sel.end);
|
|
|
- this.delta = -1;
|
|
|
- }
|
|
|
- // or Backspace and not at start
|
|
|
- } else if (delKey && this.sel.begin - 1 >= 0) {
|
|
|
- this.val = utils.removeChars(this.val, this.sel.end -1, this.sel.end);
|
|
|
- this.delta = -1;
|
|
|
- }
|
|
|
+
|
|
|
+ // Delete key (moves opposite direction)
|
|
|
+ else if (delKey && delKey == 46) {
|
|
|
+ this._delete();
|
|
|
+
|
|
|
+ // or Backspace and not at start
|
|
|
+ } else if (delKey && this.sel.begin - 1 >= 0) {
|
|
|
+ this.val = utils.removeChars(this.val, this.sel.end -1, this.sel.end);
|
|
|
+ this.delta = -1;
|
|
|
+
|
|
|
+ // or Backspace and at start - exit
|
|
|
+ } else if (delKey) {
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
// If the key is not a del key, it should convert to a str
|
|
@@ -239,6 +231,26 @@ Formatter.prototype._processKey = function (chars, delKey) { |
|
|
|
|
|
//
|
|
|
// @private
|
|
|
+// Deletes the character in front of it
|
|
|
+//
|
|
|
+Formatter.prototype._delete = function () {
|
|
|
+ // Adjust focus to make sure its not on a formatted char
|
|
|
+ while (this.chars[this.sel.begin]) {
|
|
|
+ this._nextPos();
|
|
|
+ }
|
|
|
+
|
|
|
+ // As long as we are not at the end
|
|
|
+ if (this.sel.begin < this.val.length) {
|
|
|
+ // We will simulate a delete by moving the caret to the next char
|
|
|
+ // and then deleting
|
|
|
+ this._nextPos();
|
|
|
+ this.val = utils.removeChars(this.val, this.sel.end -1, this.sel.end);
|
|
|
+ this.delta = -1;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+//
|
|
|
+// @private
|
|
|
// Quick helper method to move the caret to the next pos
|
|
|
//
|
|
|
Formatter.prototype._nextPos = function () {
|
|
@@ -317,16 +329,18 @@ Formatter.prototype._validateInpts = function () { |
|
|
// Get char inpt type
|
|
|
var inptType = this.inpts[i];
|
|
|
|
|
|
- // If improper type, or char doesnt match, remove
|
|
|
- if (!inptRegs[inptType] || !inptRegs[inptType].test(this.val.charAt(i))) {
|
|
|
- // Check bounds
|
|
|
- if (this.inpts[i]) {
|
|
|
- this.val = utils.removeChars(this.val, i, i + 1);
|
|
|
- this.focusStart--;
|
|
|
- this.newPos--;
|
|
|
- this.delta--;
|
|
|
- i--;
|
|
|
- }
|
|
|
+ // Checks
|
|
|
+ var isBadType = !inptRegs[inptType],
|
|
|
+ isInvalid = !inptRegs[inptType].test(this.val.charAt(i)),
|
|
|
+ inBounds = this.inpts[i];
|
|
|
+
|
|
|
+ // Remove if incorrect and inbounds
|
|
|
+ if ((isBadType || isInvalid) && inBounds) {
|
|
|
+ this.val = utils.removeChars(this.val, i, i + 1);
|
|
|
+ this.focusStart--;
|
|
|
+ this.newPos--;
|
|
|
+ this.delta--;
|
|
|
+ i--;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -354,6 +368,9 @@ Formatter.prototype._addChars = function () { |
|
|
} else {
|
|
|
// Avoid caching val.length, as it changes during manipulations
|
|
|
for (var j = 0; j <= this.val.length; j++) {
|
|
|
+ // When moving backwards there are some race conditions where we
|
|
|
+ // dont want to add the character
|
|
|
+ if (this.delta <= 0 && (j == this.focus)) { return true; }
|
|
|
this._addChar(j);
|
|
|
}
|
|
|
}
|
|
@@ -380,10 +397,6 @@ Formatter.prototype._addChar = function (i) { |
|
|
this.focus++;
|
|
|
}
|
|
|
|
|
|
- // When moving backwards there are some race conditions where we
|
|
|
- // dont want to add the character
|
|
|
- if (this.delta < 0 && (this.val.charAt(i) == char )) { return true; }
|
|
|
-
|
|
|
// Updateholder
|
|
|
if (this.hldrs[i]) {
|
|
|
delete this.hldrs[i];
|
|
|
0 comments on commit
04507e7