mirror of
https://github.com/tenrok/maska.git
synced 2026-06-20 20:00:34 +03:00
fix: cursor position
Better work with eager and number masks
This commit is contained in:
@@ -98,7 +98,7 @@ export class MaskInput {
|
|||||||
closure()
|
closure()
|
||||||
|
|
||||||
// if pos is null, it means element does not support setSelectionRange
|
// if pos is null, it means element does not support setSelectionRange
|
||||||
// and when cursor at the end, process only on delete event
|
// and when cursor at the end, skip non-delete event
|
||||||
if (pos === null || (pos === value.length && !isDelete)) return
|
if (pos === null || (pos === value.length && !isDelete)) return
|
||||||
|
|
||||||
const valueNew = input.value
|
const valueNew = input.value
|
||||||
@@ -106,9 +106,15 @@ export class MaskInput {
|
|||||||
const leftPartNew = valueNew.slice(0, pos)
|
const leftPartNew = valueNew.slice(0, pos)
|
||||||
const unmasked = this.processInput(input, leftPart).unmasked
|
const unmasked = this.processInput(input, leftPart).unmasked
|
||||||
const unmaskedNew = this.processInput(input, leftPartNew).unmasked
|
const unmaskedNew = this.processInput(input, leftPartNew).unmasked
|
||||||
const newPos = pos + (unmasked.length - unmaskedNew.length)
|
let posFixed = pos
|
||||||
|
|
||||||
input.setSelectionRange(newPos, newPos)
|
if (leftPart !== leftPartNew) {
|
||||||
|
posFixed += isDelete
|
||||||
|
? valueNew.length - value.length
|
||||||
|
: unmasked.length - unmaskedNew.length
|
||||||
|
}
|
||||||
|
|
||||||
|
input.setSelectionRange(posFixed, posFixed)
|
||||||
}
|
}
|
||||||
|
|
||||||
private setValue (input: HTMLInputElement, value: string): void {
|
private setValue (input: HTMLInputElement, value: string): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user