MCPcopy
hub / github.com/autoNumeric/autoNumeric / _processCharacterDeletion

Method _processCharacterDeletion

src/AutoNumeric.js:9127–9163  ·  view source on GitHub ↗

* Process the deletion of characters. * Returns `true` if the deletion is allowed (within the min and max range, according to the `overrideMinMaxLimits` option), `false` otherwise. * * @param {Event} e * @returns {boolean}

(e)

Source from the content-addressed store, hash-verified

9125 * @returns {boolean}
9126 */
9127 _processCharacterDeletion(e) {
9128 let left;
9129 let right;
9130
9131 if (!this.selection.length) {
9132 [left, right] = this._getUnformattedLeftAndRightPartAroundTheSelection();
9133 if (left === '' && right === '') {
9134 this.throwInput = false;
9135 }
9136
9137 if (this.isTrailingNegative && AutoNumericHelper.isNegative(AutoNumericHelper.getElementValue(this.domElement), this.settings.negativeSignCharacter)) {
9138 [left, right] = this._processCharacterDeletionIfTrailingNegativeSign([left, right]);
9139 } else {
9140 if (this.eventKey === AutoNumericEnum.keyName.Backspace) {
9141 left = left.substring(0, left.length - 1);
9142 } else {
9143 right = right.substring(1, right.length);
9144 }
9145 }
9146 } else {
9147 this._expandSelectionOnSign();
9148 [left, right] = this._getUnformattedLeftAndRightPartAroundTheSelection();
9149 }
9150
9151 if (!this.constructor._isWithinRangeWithOverrideOption(`${left}${right}`, this.settings)) {
9152 // If the result with the deletion would be out of the range, we prevent it
9153 return false;
9154 }
9155 if (AutoNumericHelper.getElementValue(e.target) === this.settings.currencySymbol) {
9156 return false;
9157 }
9158
9159 this._setValueParts(left, right);
9160
9161 this.throwInput = true; // fix #582: this.throwInput can be false (e.g.: by putting an invalid character previously) and we must enable this flag to ensure that input event is sent and double character is not removed, see also _onKeydown
9162 return true;
9163 }
9164
9165 /**
9166 * Return `true` if a decimal character is allowed to be typed.

Callers 1

_onKeydownMethod · 0.95

Tested by

no test coverage detected