Skip to content

Commit

Permalink
Fix cursor PR
Browse files Browse the repository at this point in the history
  • Loading branch information
nosir committed Aug 26, 2017
1 parent 3656cf6 commit 61a452b
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 155 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"form",
"input"
],
"version": "1.0.0",
"version": "1.0.1",
"author": {
"name": "Max Huang",
"email": "[email protected]",
Expand Down
44 changes: 18 additions & 26 deletions dist/cleave-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ return /******/ (function(modules) { // webpackBootstrap
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
/***/ function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function(global) {'use strict';

Expand Down Expand Up @@ -229,7 +229,6 @@ return /******/ (function(modules) { // webpackBootstrap

onInput: function (value) {
var owner = this, pps = owner.properties,
prev = value,
Util = Cleave.Util;

// case 1: delete one more character "4"
Expand Down Expand Up @@ -299,12 +298,6 @@ return /******/ (function(modules) { // webpackBootstrap
// apply blocks
pps.result = Util.getFormattedValue(value, pps.blocks, pps.blocksLength, pps.delimiter, pps.delimiters);

// nothing changed
// prevent update value to avoid caret position change
if (prev === pps.result && prev !== pps.prefix) {
return;
}

owner.updateValueState();
},

Expand Down Expand Up @@ -332,13 +325,13 @@ return /******/ (function(modules) { // webpackBootstrap
}
},

setCurrentSelection: function (endPos, oldValue, newValue) {
setCurrentSelection: function (endPos, oldValue) {
var elem = this.element;

// If cursor was at the end of value, just place it back.
// Because new value could contain additional chars.
if (oldValue.length === endPos) {
endPos = newValue.length;
return;
}

if (elem.createTextRange) {
Expand All @@ -355,21 +348,20 @@ return /******/ (function(modules) { // webpackBootstrap
var owner = this;
var endPos = owner.element.selectionEnd;
var oldValue = owner.element.value;
var newValue = owner.properties.result;

// fix Android browser type="text" input field
// cursor not jumping issue
if (owner.isAndroid) {
window.setTimeout(function () {
owner.element.value = owner.properties.result;
owner.setCurrentSelection(endPos, oldValue, newValue);
owner.setCurrentSelection(endPos, oldValue);
}, 1);

return;
}

owner.element.value = owner.properties.result;
owner.setCurrentSelection(endPos, oldValue, newValue);
owner.setCurrentSelection(endPos, oldValue);
},

setPhoneRegionCode: function (phoneRegionCode) {
Expand Down Expand Up @@ -445,9 +437,9 @@ return /******/ (function(modules) { // webpackBootstrap

/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))

/***/ }),
/***/ },
/* 1 */
/***/ (function(module, exports) {
/***/ function(module, exports) {

'use strict';

Expand Down Expand Up @@ -544,9 +536,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = NumeralFormatter;


/***/ }),
/***/ },
/* 2 */
/***/ (function(module, exports) {
/***/ function(module, exports) {

'use strict';

Expand Down Expand Up @@ -699,9 +691,9 @@ return /******/ (function(modules) { // webpackBootstrap



/***/ }),
/***/ },
/* 3 */
/***/ (function(module, exports) {
/***/ function(module, exports) {

'use strict';

Expand Down Expand Up @@ -763,9 +755,9 @@ return /******/ (function(modules) { // webpackBootstrap



/***/ }),
/***/ },
/* 4 */
/***/ (function(module, exports) {
/***/ function(module, exports) {

'use strict';

Expand Down Expand Up @@ -890,9 +882,9 @@ return /******/ (function(modules) { // webpackBootstrap



/***/ }),
/***/ },
/* 5 */
/***/ (function(module, exports) {
/***/ function(module, exports) {

'use strict';

Expand Down Expand Up @@ -1029,9 +1021,9 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = Util;


/***/ }),
/***/ },
/* 6 */
/***/ (function(module, exports) {
/***/ function(module, exports) {

/* WEBPACK VAR INJECTION */(function(global) {'use strict';

Expand Down Expand Up @@ -1113,7 +1105,7 @@ return /******/ (function(modules) { // webpackBootstrap

/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))

/***/ })
/***/ }
/******/ ])
});
;
Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-angular.min.js

Large diffs are not rendered by default.

78 changes: 11 additions & 67 deletions dist/cleave-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ return /******/ (function(modules) { // webpackBootstrap
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
/***/ function(module, exports, __webpack_require__) {

'use strict';

Expand All @@ -76,11 +76,13 @@ return /******/ (function(modules) { // webpackBootstrap
},

componentDidUpdate: function componentDidUpdate() {
if (!this.state.updateCursorPosition) {
var owner = this;

if (!owner.state.updateCursorPosition) {
return;
}

this.setCurrentSelection(this.state.cursorPosition);
owner.setCurrentSelection(owner.state.cursorPosition);
},

componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -287,8 +289,7 @@ return /******/ (function(modules) { // webpackBootstrap

onInput: function onInput(value) {
var owner = this,
pps = owner.properties,
prev = pps.result;
pps = owner.properties;

// case 1: delete one more character "4"
// 1234*| -> hit backspace -> 123|
Expand Down Expand Up @@ -357,12 +358,6 @@ return /******/ (function(modules) { // webpackBootstrap
// apply blocks
pps.result = Util.getFormattedValue(value, pps.blocks, pps.blocksLength, pps.delimiter, pps.delimiters);

// nothing changed
// prevent update value to avoid caret position change
if (prev === pps.result && prev !== pps.prefix) {
return;
}

owner.updateValueState();
},

Expand Down Expand Up @@ -390,18 +385,10 @@ return /******/ (function(modules) { // webpackBootstrap
}
},

<<<<<<< HEAD
updateValueState: function updateValueState() {
var owner = this;

if (owner.isAndroid) {
window.setTimeout(function () {
owner.setState({ value: owner.properties.result });
=======
getNextCursorPosition: function getNextCursorPosition(endPos, oldValue, newValue) {
// If cursor was at the end of value, just place it back.
// Because new value could contain additional chars.
if (oldValue.length == endPos) {
if (oldValue.length === endPos) {
return newValue.length;
}

Expand All @@ -415,10 +402,6 @@ return /******/ (function(modules) { // webpackBootstrap
updateCursorPosition: false
});

if (!elem) {
return;
}

if (elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', cursorPosition);
Expand All @@ -442,21 +425,16 @@ return /******/ (function(modules) { // webpackBootstrap
cursorPosition: nextCursorPosition,
updateCursorPosition: true
});
>>>>>>> c0e33c236397ff32ff3e4fe60aa5bd705bd3830f
}, 1);

return;
}

<<<<<<< HEAD
owner.setState({ value: owner.properties.result });
=======
owner.setState({
value: owner.properties.result,
cursorPosition: nextCursorPosition,
updateCursorPosition: true
});
>>>>>>> c0e33c236397ff32ff3e4fe60aa5bd705bd3830f
},

render: function render() {
Expand Down Expand Up @@ -497,15 +475,14 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = Cleave;

/***/ }),
/***/ },
/* 1 */
/***/ (function(module, exports) {
/***/ function(module, exports) {

module.exports = __WEBPACK_EXTERNAL_MODULE_1__;

/***/ }),
/***/ },
/* 2 */
<<<<<<< HEAD
/***/ function(module, exports, __webpack_require__) {

/**
Expand Down Expand Up @@ -1267,9 +1244,6 @@ return /******/ (function(modules) { // webpackBootstrap
/***/ },
/* 4 */
/***/ function(module, exports) {
=======
/***/ (function(module, exports) {
>>>>>>> c0e33c236397ff32ff3e4fe60aa5bd705bd3830f

// shim for using process in browser

Expand Down Expand Up @@ -1784,15 +1758,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = NumeralFormatter;

<<<<<<< HEAD
/***/ },
/* 11 */
/***/ function(module, exports) {
=======
/***/ }),
/* 3 */
/***/ (function(module, exports) {
>>>>>>> c0e33c236397ff32ff3e4fe60aa5bd705bd3830f

'use strict';

Expand Down Expand Up @@ -1952,15 +1920,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = DateFormatter;

<<<<<<< HEAD
/***/ },
/* 12 */
/***/ function(module, exports) {
=======
/***/ }),
/* 4 */
/***/ (function(module, exports) {
>>>>>>> c0e33c236397ff32ff3e4fe60aa5bd705bd3830f

'use strict';

Expand Down Expand Up @@ -2022,15 +1984,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = PhoneFormatter;

<<<<<<< HEAD
/***/ },
/* 13 */
/***/ function(module, exports) {
=======
/***/ }),
/* 5 */
/***/ (function(module, exports) {
>>>>>>> c0e33c236397ff32ff3e4fe60aa5bd705bd3830f

'use strict';

Expand Down Expand Up @@ -2153,15 +2109,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = CreditCardDetector;

<<<<<<< HEAD
/***/ },
/* 14 */
/***/ function(module, exports) {
=======
/***/ }),
/* 6 */
/***/ (function(module, exports) {
>>>>>>> c0e33c236397ff32ff3e4fe60aa5bd705bd3830f

'use strict';

Expand Down Expand Up @@ -2294,15 +2244,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = Util;

<<<<<<< HEAD
/***/ },
/* 15 */
/***/ function(module, exports) {
=======
/***/ }),
/* 7 */
/***/ (function(module, exports) {
>>>>>>> c0e33c236397ff32ff3e4fe60aa5bd705bd3830f

/* WEBPACK VAR INJECTION */(function(global) {'use strict';

Expand Down Expand Up @@ -2380,7 +2324,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = DefaultProperties;
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))

/***/ })
/***/ }
/******/ ])
});
;
8 changes: 2 additions & 6 deletions dist/cleave-react.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 61a452b

Please sign in to comment.