|
@@ -245,8 +245,17 @@ Formatter.prototype._processKey = function (chars, delKey,ingoreCaret) { |
|
|
|
|
|
// 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;
|
|
|
+
|
|
|
+ // Always have a delta of at least -1 for the character being deleted.
|
|
|
+ this.delta -= 1;
|
|
|
+
|
|
|
+ // Count number of additional format chars to be deleted. (A group of multiple format chars should be deleted like one value char.)
|
|
|
+ while (this.chars[this.focus-1]) {
|
|
|
+ this.delta--;
|
|
|
+ this.focus--;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.val = utils.removeChars(this.val, this.sel.end + this.delta, this.sel.end);
|
|
|
|
|
|
// or Backspace and at start - exit
|
|
|
} else if (delKey) {
|
|
@@ -310,6 +319,7 @@ Formatter.prototype._formatValue = function (ignoreCaret) { |
|
|
|
|
|
// Validate inputs
|
|
|
this._validateInpts();
|
|
|
+
|
|
|
// Add formatted characters
|
|
|
this._addChars();
|
|
|
|
|
@@ -407,11 +417,12 @@ Formatter.prototype._addChars = function () { |
|
|
this.focus++;
|
|
|
}
|
|
|
} else {
|
|
|
- // Avoid caching val.length, as it changes during manipulations
|
|
|
+ // Avoid caching val.length and this.focus, as they may change in _addChar.
|
|
|
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; }
|
|
|
+ // When moving backwards, i.e. delting characters, don't add format characters past focus point.
|
|
|
+ if ( (this.delta <= 0 && j === this.focus && this.chars[j] === undefined) || (this.focus === 0) ) { return true; }
|
|
|
+
|
|
|
+ // Place character in current position of the formatted string.
|
|
|
this._addChar(j);
|
|
|
}
|
|
|
}
|
|
|
0 comments on commit
1239bc9