Skip to content

Commit

Permalink
fix(#1000): cursor position after paste to input in mask with separator
Browse files Browse the repository at this point in the history
  • Loading branch information
GlebChiz committed Apr 25, 2022
1 parent a22f7ef commit a102e53
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<a name="13.1.11"></a>

# 13.1.11 (2022-04-25)

### Fix

- Fix ([#1000](https://github.com/JsDaddy/ngx-mask/issues/1000))

<a name="13.1.10"></a>

# 13.1.10 (2022-04-18)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "13.1.10",
"version": "13.1.11",
"description": "awesome ngx mask",
"license": "MIT",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mask-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "13.1.10",
"version": "13.1.11",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
7 changes: 6 additions & 1 deletion projects/ngx-mask-lib/src/lib/mask-applier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,12 @@ export class MaskApplierService {
newPosition++;
}

let actualShift: number = justPasted ? cursor : this._shift.has(position) ? shift : 0;
let actualShift: number =
justPasted && !maskExpression.startsWith('separator')
? cursor
: this._shift.has(position)
? shift
: 0;
if (stepBack) {
actualShift--;
}
Expand Down
22 changes: 22 additions & 0 deletions projects/ngx-mask-lib/src/test/copy-paste.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,26 @@ describe('Event: paste', () => {

expect(inputDebuggerElement.nativeElement.selectionStart).toBe(15);
});
it('After paste to control cursor should be on the end of input for mask with separator', () => {
component.mask = 'separator.0';
component.thousandSeparator = ',';
fixture.detectChanges();

const inputDebuggerElement = fixture.debugElement.query(By.css('#mask'));

const pasteData = new DataTransfer();
pasteData.setData('text', '1234567');
inputDebuggerElement.triggerEventHandler('paste', pasteData);

inputDebuggerElement.nativeElement.value = pasteData.getData('text/plain');
inputDebuggerElement.triggerEventHandler('input', {
target: inputDebuggerElement.nativeElement,
});

fixture.detectChanges();

expect(inputDebuggerElement.nativeElement.value).toBe('1,234,567');

expect(inputDebuggerElement.nativeElement.selectionStart).toBe(9);
});
});

0 comments on commit a102e53

Please sign in to comment.