Permalink
Browse files

Fixing issue when deleting with cursor on mask literal

  • Loading branch information...
1 parent 2826235 commit 228bd004e18254fedd16b34641b9178860364665 @digitalBush digitalBush committed Feb 11, 2011
Showing with 30 additions and 42 deletions.
  1. +28 −40 spec/Delete.spec.js
  2. +2 −2 src/jquery.maskedinput.js
View
@@ -1,45 +1,33 @@
-describe("Delete Specifications", function() {
- var input;
-
- beforeEach(function(){
- input =
- $("<input />")
- .appendTo("body");
+feature("Deleting characters", function() {
+ scenario('Hitting delete key with cursor on a mask literal',function(){
+ given("an input with a mask definition of '9-99'", function(){
+ input
+ .mask("9-99")
+ .mashKeys("123")
+
+ });
+
+ given("the input has cursor positioned on literal", function(){
+ input
+ .caret(1);
+ });
+ when("hitting the delete key",function(){
+ input.mashKeys(function(keys){keys.type(keys.delete)});
+ });
+
+ then("value should be correct",function(){
+ expect(input).toHaveValue('1-3_');
+ });
+
+ and("caret position should be correct",function(){
+ expect(input.caret().begin).toEqual(2);
+ });
});
-
- afterEach(function(){
- input.remove();
- });
-
+});
+
+
+describe("Delete Specifications", function() {
describe("when deleting",function(){
- describe("with cursor is on a literal",function(){
- beforeEach(function(){
- runs(function(){
- input
- .mask("9-99")
- .focus();
- });
- waits(1);
- runs(function(){
- input
- .mashKeys("123")
- .caret(1)
- .mashKeys(function(keys){keys.type(keys.delete)});
- });
- });
-
- it("should have the correct placeholder text", function(){
- expect(input).toHaveValue('1-3_');
- });
-
- it("should have the correct caret position", function(){
- var caret=input.caret();
- expect(caret.begin).toEqual(2);
- expect(caret.end).toEqual(2);
- });
- });
-
-
describe("with character to right of current position which matches current mask definition",function(){
beforeEach(function(){
input
@@ -132,8 +132,8 @@
end = pos.end;
if(end-begin==0){
- end=k==46?seekNext(end-1):end;
- begin=k!=46?seekPrev(begin):begin;
+ end=begin=k!=46?seekPrev(begin):seekNext(begin-1);
+ end=k==46?seekNext(end):end;
}
clearBuffer(begin, end);
shiftL(begin,end-1);

0 comments on commit 228bd00

Please sign in to comment.