Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions packages/primeng/src/inputmask/inputmask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ export class InputMaskDirective extends BaseComponent<InputMaskPassThrough> {
return pos;
}

/**
* Count the number of fixed (non-editable) mask characters in the range [from, to).
* Fixed characters are those where tests[k] is null (e.g. separators like '.' or '/').
*/
private countFixedChars(from: number, to: number): number {
let count = 0;
for (let k = from; k < to; k++) {
if (!this.tests[k]) count++;
}
return count;
}

shiftL(begin: number, end: number) {
let i, j;

Expand All @@ -507,6 +519,12 @@ export class InputMaskDirective extends BaseComponent<InputMaskPassThrough> {

for (i = begin, j = this.seekNext(end); i < (this.len as number); i++) {
if (this.tests[i]) {
// Stop shifting if j has crossed more fixed-mask separators than i has.
// This prevents digits from bleeding across section boundaries (e.g. 99.99.9999).
if (this.countFixedChars(begin, i + 1) !== this.countFixedChars(end + 1, j + 1)) {
break;
}

if (j < (this.len as number) && this.tests[i].test(this.buffer[j])) {
this.buffer[i] = this.buffer[j];
this.buffer[j] = this.getPlaceholder(j);
Expand Down Expand Up @@ -1070,6 +1088,18 @@ export class InputMask extends BaseInput<InputMaskPassThrough> {
return pos;
}

/**
* Count the number of fixed (non-editable) mask characters in the range [from, to).
* Fixed characters are those where tests[k] is null (e.g. separators like '.' or '/').
*/
private countFixedChars(from: number, to: number): number {
let count = 0;
for (let k = from; k < to; k++) {
if (!this.tests[k]) count++;
}
return count;
}

shiftL(begin: number, end: number) {
let i, j;

Expand All @@ -1079,6 +1109,12 @@ export class InputMask extends BaseInput<InputMaskPassThrough> {

for (i = begin, j = this.seekNext(end); i < (this.len as number); i++) {
if (this.tests[i]) {
// Stop shifting if j has crossed more fixed-mask separators than i has.
// This prevents digits from bleeding across section boundaries (e.g. 99.99.9999).
if (this.countFixedChars(begin, i + 1) !== this.countFixedChars(end + 1, j + 1)) {
break;
}

if (j < (this.len as number) && this.tests[i].test(this.buffer[j])) {
this.buffer[i] = this.buffer[j];
this.buffer[j] = this.getPlaceholder(j);
Expand Down
Loading