Skip to content

Commit 4a541bf

Browse files
authored
Merge branch 'master' into bpachilova/fix-12608
2 parents 3174dd9 + 2cde0ce commit 4a541bf

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

projects/igniteui-angular/src/lib/directives/mask/mask-parsing.service.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export class MaskParsingService {
9191
const chars = Array.from(value);
9292
let cursor = start;
9393
end = Math.min(end, maskedValue.length);
94+
let initialMaskedValue = maskedValue;
9495

9596
for (let i = start; i < end || (chars.length && i < maskedValue.length); i++) {
9697
if (literalsPositions.indexOf(i) !== -1) {
@@ -114,10 +115,21 @@ export class MaskParsingService {
114115
maskedValue = this.replaceCharAt(maskedValue, i, char);
115116
}
116117

117-
if (Math.abs(end - start) >= 1) {
118-
// set cursor to be max between last cursor pos and the calculated `end`
119-
// since on `delete` the cursor should move forward
120-
cursor = Math.max(cursor, end);
118+
if (value.length <= 1) {
119+
let isDelete = false;
120+
cursor = start;
121+
for (let i = 0; i < literalsPositions.length; i++) {
122+
if (value === '') {
123+
// on `delete` the cursor should move forward
124+
cursor = Math.max(cursor, end);
125+
isDelete = true;
126+
} else if (cursor === literalsPositions[i]) {
127+
cursor = literalsPositions[i] + 1;
128+
}
129+
}
130+
if (!isDelete && initialMaskedValue !== maskedValue) {
131+
cursor++;
132+
}
121133
}
122134

123135
return { value: maskedValue, end: cursor};

0 commit comments

Comments
 (0)