Skip to content

Commit d5b1273

Browse files
committed
fix(backspace): Added functionality to move the cursor back when backspacing separators
1 parent e572857 commit d5b1273

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: src/input.service.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class InputService {
4949
}
5050

5151
clearMask(rawValue: string): number {
52-
52+
5353
if (this.isNullable() && rawValue === "")
5454
return null;
5555

@@ -81,7 +81,7 @@ export class InputService {
8181
this.rawValue = null;
8282
return;
8383
}
84-
84+
8585
let selectionEnd = this.inputSelection.selectionEnd;
8686
let selectionStart = this.inputSelection.selectionStart;
8787

@@ -90,10 +90,11 @@ export class InputService {
9090
selectionStart = this.rawValue.length - this.options.suffix.length;
9191
}
9292

93+
const move = this.rawValue.substr(selectionStart - 1, 1).match(/\d/) ? 0 : 1;
9394
selectionEnd = keyCode == 46 || keyCode == 63272 ? selectionEnd + 1 : selectionEnd;
9495
selectionStart = keyCode == 8 ? selectionStart - 1 : selectionStart;
9596
this.rawValue = this.rawValue.substring(0, selectionStart) + this.rawValue.substring(selectionEnd, this.rawValue.length);
96-
this.updateFieldValue(selectionStart);
97+
this.updateFieldValue(selectionStart - move);
9798
}
9899

99100
updateFieldValue(selectionStart?: number): void {

0 commit comments

Comments
 (0)