diff --git a/packages/primevue/src/inputnumber/InputNumber.vue b/packages/primevue/src/inputnumber/InputNumber.vue index af0026a6c..9d7a4b30e 100755 --- a/packages/primevue/src/inputnumber/InputNumber.vue +++ b/packages/primevue/src/inputnumber/InputNumber.vue @@ -634,12 +634,12 @@ export default { let newValueStr; if (sign.isMinusSign) { - const value = this.parseValue(inputValue); + const isNewMinusSign = minusCharIndex === -1; - if (selectionStart === 0 || value === 0) { + if (selectionStart === 0 || selectionStart === currencyCharIndex + 1) { newValueStr = inputValue; - if (minusCharIndex === -1 || selectionEnd !== 0) { + if (isNewMinusSign || selectionEnd !== 0) { newValueStr = this.insertText(inputValue, text, 0, selectionEnd); } @@ -784,16 +784,8 @@ export default { if (valueStr != null) { newValue = this.parseValue(valueStr); - - if (!newValue && !this.allowEmpty) { - newValue = 0; - this.updateInput(newValue, insertedValueStr, operation, valueStr); - const cursorPos = this.prefix ? this.prefix.length + 1 : 1; - - this.$refs.input.$el.setSelectionRange(cursorPos, cursorPos); - } else { - this.updateInput(newValue, insertedValueStr, operation, valueStr); - } + newValue = !newValue && !this.allowEmpty ? this.min || 0 : newValue; + this.updateInput(newValue, insertedValueStr, operation, valueStr); this.handleOnInput(event, currentValue, newValue); } @@ -874,7 +866,16 @@ export default { this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd); } else if (newLength === currentLength) { if (operation === 'insert' || operation === 'delete-back-single') { - this.$refs.input.$el.setSelectionRange(selectionEnd, selectionEnd); + let newSelectionEnd = selectionEnd; + + if (insertedValueStr === '0') { + newSelectionEnd = selectionEnd + 1; + } else { + console.log(Number(this.isDecimalSign(value) || this.isDecimalSign(insertedValueStr))); + newSelectionEnd = newSelectionEnd + Number(this.isDecimalSign(value) || this.isDecimalSign(insertedValueStr)); + } + + this.$refs.input.$el.setSelectionRange(newSelectionEnd, newSelectionEnd); } else if (operation === 'delete-single') { this.$refs.input.$el.setSelectionRange(selectionEnd - 1, selectionEnd - 1); } else if (operation === 'delete-range' || operation === 'spin') {