Browse Source

fix lvp position when overwriting a selection

Robin Herbots 12 years ago
parent
commit
82f6ae22bf

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 
 build.major = 2
 build.major = 2
 build.minor = 2
 build.minor = 2
-build.revision = 64
+build.revision = 65
 
 
 target = jquery.inputmask.bundle.js
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js
 target.min = jquery.inputmask.bundle.min.js

+ 1 - 1
component.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "jquery.inputmask",
     "name": "jquery.inputmask",
-    "version": "2.2.64",
+    "version": "2.2.65",
     "main": "./dist/jquery.inputmask.bundle.js",
     "main": "./dist/jquery.inputmask.bundle.js",
     "dependencies": {
     "dependencies": {
         "jquery": ">=1.5"
         "jquery": ">=1.5"

BIN
dist/jQuery.InputMask.2.2.64.nupkg


BIN
dist/jQuery.InputMask.2.2.65.nupkg


+ 25 - 19
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 2.2.64
+* Version: 2.2.65
 */
 */
 
 
 (function ($) {
 (function ($) {
@@ -63,12 +63,12 @@
                 ignorables: [9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
                 ignorables: [9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
                 getMaskLength: function (buffer, greedy, repeat, currentBuffer, opts) {
                 getMaskLength: function (buffer, greedy, repeat, currentBuffer, opts) {
                     var calculatedLength = buffer.length;
                     var calculatedLength = buffer.length;
-                    if (!greedy) { 
-                     	if(repeat == "*") {
-                     		calculatedLength = currentBuffer.length + 1;
-                     	} else if(repeat > 1) {
-                        	calculatedLength += (buffer.length * (repeat - 1));
-                    	}
+                    if (!greedy) {
+                        if (repeat == "*") {
+                            calculatedLength = currentBuffer.length + 1;
+                        } else if (repeat > 1) {
+                            calculatedLength += (buffer.length * (repeat - 1));
+                        }
                     }
                     }
                     return calculatedLength;
                     return calculatedLength;
                 }
                 }
@@ -232,7 +232,7 @@
             }
             }
             function getMaskTemplate(mask) {
             function getMaskTemplate(mask) {
                 var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
                 var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
-                if(repeat == "*") greedy = false;
+                if (repeat == "*") greedy = false;
                 if (mask.length == 1 && greedy == false) { opts.placeholder = ""; } //hide placeholder with single non-greedy mask
                 if (mask.length == 1 && greedy == false) { opts.placeholder = ""; } //hide placeholder with single non-greedy mask
                 var singleMask = $.map(mask.split(""), function (element, index) {
                 var singleMask = $.map(mask.split(""), function (element, index) {
                     var outElem = [];
                     var outElem = [];
@@ -1309,9 +1309,9 @@
                                 }
                                 }
 
 
                                 //should we clear a possible selection??
                                 //should we clear a possible selection??
-                                var isSelection = (pos.end - pos.begin) > 1 || ((pos.end - pos.begin) == 1 && opts.insertMode);
+                                var isSelection = (pos.end - pos.begin) > 1 || ((pos.end - pos.begin) == 1 && opts.insertMode), redetermineLVP = false;
                                 if (isSelection) {
                                 if (isSelection) {
-                                    var initialIndex = activeMasksetIndex, redetermineLVP = false;
+                                    var initialIndex = activeMasksetIndex;
                                     $.each(masksets, function (ndx, lmnt) {
                                     $.each(masksets, function (ndx, lmnt) {
                                         activeMasksetIndex = ndx;
                                         activeMasksetIndex = ndx;
                                         getActiveMaskSet()["undoBuffer"] = getActiveBuffer().join(''); //init undobuffer for recovery when not valid
                                         getActiveMaskSet()["undoBuffer"] = getActiveBuffer().join(''); //init undobuffer for recovery when not valid
@@ -1327,7 +1327,7 @@
                                             }
                                             }
                                         }
                                         }
                                         if (getActiveMaskSet()["lastValidPosition"] > pos.begin && getActiveMaskSet()["lastValidPosition"] < posend) {
                                         if (getActiveMaskSet()["lastValidPosition"] > pos.begin && getActiveMaskSet()["lastValidPosition"] < posend) {
-                                            getActiveMaskSet()["lastValidPosition"] = isRTL ? posend : pos.begin;
+                                            getActiveMaskSet()["lastValidPosition"] = isRTL ? seekNext(posend) : seekPrevious(pos.begin);
                                         } else {
                                         } else {
                                             redetermineLVP = true;
                                             redetermineLVP = true;
                                         }
                                         }
@@ -1378,6 +1378,9 @@
                                                             maskL = buffer.length;
                                                             maskL = buffer.length;
                                                         }
                                                         }
                                                         shiftL(firstUnmaskedPosition, p, c);
                                                         shiftL(firstUnmaskedPosition, p, c);
+                                                        if (redetermineLVP && getActiveMaskSet()["lastValidPosition"] <= p) {
+                                                            getActiveMaskSet()["lastValidPosition"] = seekPrevious(getActiveMaskSet()["lastValidPosition"]);
+                                                        }
                                                     } else getActiveMaskSet()["writeOutBuffer"] = false;
                                                     } else getActiveMaskSet()["writeOutBuffer"] = false;
                                                 } else setBufferElement(buffer, p, c, true, isRTL);
                                                 } else setBufferElement(buffer, p, c, true, isRTL);
                                             }
                                             }
@@ -1406,9 +1409,12 @@
                                                     while (getBufferElement(bfrClone, lastUnmaskedPosition, true) != getPlaceHolder(lastUnmaskedPosition) && lastUnmaskedPosition >= p) {
                                                     while (getBufferElement(bfrClone, lastUnmaskedPosition, true) != getPlaceHolder(lastUnmaskedPosition) && lastUnmaskedPosition >= p) {
                                                         lastUnmaskedPosition = lastUnmaskedPosition == 0 ? -1 : seekPrevious(lastUnmaskedPosition);
                                                         lastUnmaskedPosition = lastUnmaskedPosition == 0 ? -1 : seekPrevious(lastUnmaskedPosition);
                                                     }
                                                     }
-                                                    if (lastUnmaskedPosition >= p)
+                                                    if (lastUnmaskedPosition >= p) {
                                                         shiftR(p, buffer.length, c);
                                                         shiftR(p, buffer.length, c);
-                                                    else getActiveMaskSet()["writeOutBuffer"] = false;
+                                                        if (redetermineLVP && getActiveMaskSet()["lastValidPosition"] >= p) {
+                                                            getActiveMaskSet()["lastValidPosition"] = seekNext(getActiveMaskSet()["lastValidPosition"]);
+                                                        }
+                                                    } else getActiveMaskSet()["writeOutBuffer"] = false;
                                                 } else setBufferElement(buffer, p, c, true, isRTL);
                                                 } else setBufferElement(buffer, p, c, true, isRTL);
                                             }
                                             }
                                             getActiveMaskSet()["p"] = seekNext(p);
                                             getActiveMaskSet()["p"] = seekNext(p);
@@ -1470,17 +1476,17 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.2.64
+Version: 2.2.65
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
 (function ($) {
 (function ($) {
     //extra definitions
     //extra definitions
     $.extend($.inputmask.defaults.definitions, {
     $.extend($.inputmask.defaults.definitions, {
-        'A': { //auto uppercasing
+        'A': { 
             validator: "[A-Za-z]",
             validator: "[A-Za-z]",
             cardinality: 1,
             cardinality: 1,
-            casing: "upper"
+            casing: "upper" //auto uppercasing
         },
         },
         '#': {
         '#': {
             validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
             validator: "[A-Za-z\u0410-\u044F\u0401\u04510-9]",
@@ -1572,7 +1578,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.2.64
+Version: 2.2.65
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2041,7 +2047,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.2.64
+Version: 2.2.65
 
 
 Optional extensions on the jquery.inputmask base
 Optional extensions on the jquery.inputmask base
 */
 */
@@ -2208,7 +2214,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2013 Robin Herbots
 Copyright (c) 2010 - 2013 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 2.2.64
+Version: 2.2.65
 
 
 Regex extensions on the jquery.inputmask base
 Regex extensions on the jquery.inputmask base
 Allows for using regular expressions as a mask
 Allows for using regular expressions as a mask

File diff suppressed because it is too large
+ 60 - 60
dist/jquery.inputmask.bundle.min.js


File diff suppressed because it is too large
+ 39 - 39
dist/min/jquery.inputmask.js


+ 1 - 1
jquery.inputmask.jquery.json

@@ -8,7 +8,7 @@
 		"inputmask",
 		"inputmask",
 		"mask"
 		"mask"
     ],
     ],
-    "version": "2.2.64",
+    "version": "2.2.65",
     "author": {
     "author": {
         "name": "Robin Herbots",
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 18 - 12
js/jquery.inputmask.js

@@ -63,12 +63,12 @@
                 ignorables: [9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
                 ignorables: [9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123],
                 getMaskLength: function (buffer, greedy, repeat, currentBuffer, opts) {
                 getMaskLength: function (buffer, greedy, repeat, currentBuffer, opts) {
                     var calculatedLength = buffer.length;
                     var calculatedLength = buffer.length;
-                    if (!greedy) { 
-                     	if(repeat == "*") {
-                     		calculatedLength = currentBuffer.length + 1;
-                     	} else if(repeat > 1) {
-                        	calculatedLength += (buffer.length * (repeat - 1));
-                    	}
+                    if (!greedy) {
+                        if (repeat == "*") {
+                            calculatedLength = currentBuffer.length + 1;
+                        } else if (repeat > 1) {
+                            calculatedLength += (buffer.length * (repeat - 1));
+                        }
                     }
                     }
                     return calculatedLength;
                     return calculatedLength;
                 }
                 }
@@ -232,7 +232,7 @@
             }
             }
             function getMaskTemplate(mask) {
             function getMaskTemplate(mask) {
                 var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
                 var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
-                if(repeat == "*") greedy = false;
+                if (repeat == "*") greedy = false;
                 if (mask.length == 1 && greedy == false) { opts.placeholder = ""; } //hide placeholder with single non-greedy mask
                 if (mask.length == 1 && greedy == false) { opts.placeholder = ""; } //hide placeholder with single non-greedy mask
                 var singleMask = $.map(mask.split(""), function (element, index) {
                 var singleMask = $.map(mask.split(""), function (element, index) {
                     var outElem = [];
                     var outElem = [];
@@ -1309,9 +1309,9 @@
                                 }
                                 }
 
 
                                 //should we clear a possible selection??
                                 //should we clear a possible selection??
-                                var isSelection = (pos.end - pos.begin) > 1 || ((pos.end - pos.begin) == 1 && opts.insertMode);
+                                var isSelection = (pos.end - pos.begin) > 1 || ((pos.end - pos.begin) == 1 && opts.insertMode), redetermineLVP = false;
                                 if (isSelection) {
                                 if (isSelection) {
-                                    var initialIndex = activeMasksetIndex, redetermineLVP = false;
+                                    var initialIndex = activeMasksetIndex;
                                     $.each(masksets, function (ndx, lmnt) {
                                     $.each(masksets, function (ndx, lmnt) {
                                         activeMasksetIndex = ndx;
                                         activeMasksetIndex = ndx;
                                         getActiveMaskSet()["undoBuffer"] = getActiveBuffer().join(''); //init undobuffer for recovery when not valid
                                         getActiveMaskSet()["undoBuffer"] = getActiveBuffer().join(''); //init undobuffer for recovery when not valid
@@ -1327,7 +1327,7 @@
                                             }
                                             }
                                         }
                                         }
                                         if (getActiveMaskSet()["lastValidPosition"] > pos.begin && getActiveMaskSet()["lastValidPosition"] < posend) {
                                         if (getActiveMaskSet()["lastValidPosition"] > pos.begin && getActiveMaskSet()["lastValidPosition"] < posend) {
-                                            getActiveMaskSet()["lastValidPosition"] = isRTL ? posend : pos.begin;
+                                            getActiveMaskSet()["lastValidPosition"] = isRTL ? seekNext(posend) : seekPrevious(pos.begin);
                                         } else {
                                         } else {
                                             redetermineLVP = true;
                                             redetermineLVP = true;
                                         }
                                         }
@@ -1378,6 +1378,9 @@
                                                             maskL = buffer.length;
                                                             maskL = buffer.length;
                                                         }
                                                         }
                                                         shiftL(firstUnmaskedPosition, p, c);
                                                         shiftL(firstUnmaskedPosition, p, c);
+                                                        if (redetermineLVP && getActiveMaskSet()["lastValidPosition"] <= p) {
+                                                            getActiveMaskSet()["lastValidPosition"] = seekPrevious(getActiveMaskSet()["lastValidPosition"]);
+                                                        }
                                                     } else getActiveMaskSet()["writeOutBuffer"] = false;
                                                     } else getActiveMaskSet()["writeOutBuffer"] = false;
                                                 } else setBufferElement(buffer, p, c, true, isRTL);
                                                 } else setBufferElement(buffer, p, c, true, isRTL);
                                             }
                                             }
@@ -1406,9 +1409,12 @@
                                                     while (getBufferElement(bfrClone, lastUnmaskedPosition, true) != getPlaceHolder(lastUnmaskedPosition) && lastUnmaskedPosition >= p) {
                                                     while (getBufferElement(bfrClone, lastUnmaskedPosition, true) != getPlaceHolder(lastUnmaskedPosition) && lastUnmaskedPosition >= p) {
                                                         lastUnmaskedPosition = lastUnmaskedPosition == 0 ? -1 : seekPrevious(lastUnmaskedPosition);
                                                         lastUnmaskedPosition = lastUnmaskedPosition == 0 ? -1 : seekPrevious(lastUnmaskedPosition);
                                                     }
                                                     }
-                                                    if (lastUnmaskedPosition >= p)
+                                                    if (lastUnmaskedPosition >= p) {
                                                         shiftR(p, buffer.length, c);
                                                         shiftR(p, buffer.length, c);
-                                                    else getActiveMaskSet()["writeOutBuffer"] = false;
+                                                        if (redetermineLVP && getActiveMaskSet()["lastValidPosition"] >= p) {
+                                                            getActiveMaskSet()["lastValidPosition"] = seekNext(getActiveMaskSet()["lastValidPosition"]);
+                                                        }
+                                                    } else getActiveMaskSet()["writeOutBuffer"] = false;
                                                 } else setBufferElement(buffer, p, c, true, isRTL);
                                                 } else setBufferElement(buffer, p, c, true, isRTL);
                                             }
                                             }
                                             getActiveMaskSet()["p"] = seekNext(p);
                                             getActiveMaskSet()["p"] = seekNext(p);