Skip to content

Commit

Permalink
fix #850
Browse files Browse the repository at this point in the history
  • Loading branch information
uNmAnNeR committed Apr 27, 2023
1 parent 4292f69 commit 27c5774
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/imask/src/masked/dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,26 @@ MaskedDynamic.DEFAULTS = {

// simulate input
const inputs = masked.compiledMasks.map((m, index) => {
const isCurrent = masked.currentMask === m;
const startInputPos = isCurrent ? m.value.length : m.nearestInputPos(m.value.length, DIRECTION.FORCE_LEFT);

if (m.rawInputValue !== inputValue) {
m.reset();
m.append(inputValue, { raw: true });
} else {
m.remove(m.nearestInputPos(m.value.length, DIRECTION.FORCE_LEFT));
} else if (!isCurrent) {
m.remove(startInputPos);
}
m.append(appended, masked.currentMaskFlags(flags));
m.appendTail(tail);
const weight = m.rawInputValue.length;
const totalInputPositions = m.totalInputPositions(0, m.nearestInputPos(m.value.length, DIRECTION.FORCE_LEFT));

return { weight, totalInputPositions, index };
return {
index,
weight: m.rawInputValue.length,
totalInputPositions: m.totalInputPositions(
0,
Math.max(startInputPos, m.nearestInputPos(m.value.length, DIRECTION.FORCE_LEFT)),
),
};
});

// pop masks with longer values first
Expand Down

0 comments on commit 27c5774

Please sign in to comment.