Permalink
Browse files

Better functioning delete key

1 parent ea657a9 commit 482c06113f0647317df45aa5c2955ee8036734fe @jaridmargolin jaridmargolin committed Oct 29, 2013
Showing with 80 additions and 38 deletions.
  1. +26 −12 lib/formatter.js
  2. +1 −1 lib/formatter.min.js
  3. +26 −12 lib/jquery.formatter.js
  4. +1 −1 lib/jquery.formatter.min.js
  5. +26 −12 src/formatter.js
View
@@ -176,19 +176,24 @@ 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 Backspace key and a Delete key
+ // If delKey
else if (delKey) {
- // Key is delete. Make sure not at str end
- if (delKey == 46 && this.sel.begin < this.val.length) {
- // We will simulate a delete by moving the caret forward
- // by 1 and then deleting
- this.sel.end ++;
- this.sel.begin ++;
- this.val = utils.removeChars(this.val, this.sel.end -1, this.sel.end);
- this.delta = -1;
- // Key is backspace. Make sure not at str start
- } else if (this.sel.begin - 1 >= 0) {
+ // 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;
}
@@ -207,6 +212,15 @@ Formatter.prototype._processKey = function (chars, delKey) {
//
// @private
+// Quick helper method to move the caret to the next pos
+//
+Formatter.prototype._nextPos = function () {
+ this.sel.end ++;
+ this.sel.begin ++;
+};
+
+//
+// @private
// Alter element value to display characters matching the provided
// instance pattern. Also responsible for updatin
//
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -173,19 +173,24 @@ 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 Backspace key and a Delete key
+ // If delKey
else if (delKey) {
- // Key is delete. Make sure not at str end
- if (delKey == 46 && this.sel.begin < this.val.length) {
- // We will simulate a delete by moving the caret forward
- // by 1 and then deleting
- this.sel.end ++;
- this.sel.begin ++;
- this.val = utils.removeChars(this.val, this.sel.end -1, this.sel.end);
- this.delta = -1;
- // Key is backspace. Make sure not at str start
- } else if (this.sel.begin - 1 >= 0) {
+ // 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;
}
@@ -204,6 +209,15 @@ Formatter.prototype._processKey = function (chars, delKey) {
//
// @private
+// Quick helper method to move the caret to the next pos
+//
+Formatter.prototype._nextPos = function () {
+ this.sel.end ++;
+ this.sel.begin ++;
+};
+
+//
+// @private
// Alter element value to display characters matching the provided
// instance pattern. Also responsible for updatin
//
Oops, something went wrong.

0 comments on commit 482c061

Please sign in to comment.