Skip to content

Commit 228bd00

Browse files
committed
Fixing issue when deleting with cursor on mask literal
1 parent 2826235 commit 228bd00

File tree

2 files changed

+30
-42
lines changed

2 files changed

+30
-42
lines changed

spec/Delete.spec.js

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
1-
describe("Delete Specifications", function() {
2-
var input;
3-
4-
beforeEach(function(){
5-
input =
6-
$("<input />")
7-
.appendTo("body");
1+
feature("Deleting characters", function() {
2+
scenario('Hitting delete key with cursor on a mask literal',function(){
3+
given("an input with a mask definition of '9-99'", function(){
4+
input
5+
.mask("9-99")
6+
.mashKeys("123")
7+
8+
});
9+
10+
given("the input has cursor positioned on literal", function(){
11+
input
12+
.caret(1);
13+
});
14+
when("hitting the delete key",function(){
15+
input.mashKeys(function(keys){keys.type(keys.delete)});
16+
});
17+
18+
then("value should be correct",function(){
19+
expect(input).toHaveValue('1-3_');
20+
});
21+
22+
and("caret position should be correct",function(){
23+
expect(input.caret().begin).toEqual(2);
24+
});
825
});
9-
10-
afterEach(function(){
11-
input.remove();
12-
});
13-
26+
});
27+
28+
29+
describe("Delete Specifications", function() {
1430
describe("when deleting",function(){
15-
describe("with cursor is on a literal",function(){
16-
beforeEach(function(){
17-
runs(function(){
18-
input
19-
.mask("9-99")
20-
.focus();
21-
});
22-
waits(1);
23-
runs(function(){
24-
input
25-
.mashKeys("123")
26-
.caret(1)
27-
.mashKeys(function(keys){keys.type(keys.delete)});
28-
});
29-
});
30-
31-
it("should have the correct placeholder text", function(){
32-
expect(input).toHaveValue('1-3_');
33-
});
34-
35-
it("should have the correct caret position", function(){
36-
var caret=input.caret();
37-
expect(caret.begin).toEqual(2);
38-
expect(caret.end).toEqual(2);
39-
});
40-
});
41-
42-
4331
describe("with character to right of current position which matches current mask definition",function(){
4432
beforeEach(function(){
4533
input

src/jquery.maskedinput.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@
132132
end = pos.end;
133133

134134
if(end-begin==0){
135-
end=k==46?seekNext(end-1):end;
136-
begin=k!=46?seekPrev(begin):begin;
135+
end=begin=k!=46?seekPrev(begin):seekNext(begin-1);
136+
end=k==46?seekNext(end):end;
137137
}
138138
clearBuffer(begin, end);
139139
shiftL(begin,end-1);

0 commit comments

Comments
 (0)