Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Ignore hotkeys when shift is down #37

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion build/ng-tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ tagsInput.directive('tagsInput', ["$timeout","$document","tagsInputConfig", func
return;
}

if (hotkeys.indexOf(e.keyCode) === -1) {
if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey || hotkeys.indexOf(e.keyCode) === -1) {
return;
}

Expand Down Expand Up @@ -248,6 +248,7 @@ tagsInput.directive('tagsInput', ["$timeout","$document","tagsInputConfig", func
};
}]);


/**
* @ngdoc directive
* @name tagsInput.directive:autoComplete
Expand Down
Binary file modified build/ng-tags-input.min.zip
Binary file not shown.
Binary file modified build/ng-tags-input.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ tagsInput.directive('tagsInput', function($timeout, $document, tagsInputConfig)
return;
}

if (hotkeys.indexOf(e.keyCode) === -1) {
if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey || hotkeys.indexOf(e.keyCode) === -1) {
return;
}

Expand Down Expand Up @@ -234,4 +234,4 @@ tagsInput.directive('tagsInput', function($timeout, $document, tagsInputConfig)
});
}
};
});
});
32 changes: 26 additions & 6 deletions test/tags-input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ describe('tags-input-directive', function() {
function newTag(tag, key) {
key = key || KEYS.enter;

for(var i = 0; i < tag.length; i++) {
sendKeyPress(tag.charCodeAt(i));
}
sendKeyPresses(tag);
sendKeyDown(key);
}

function sendKeyPress(charCode) {
function sendKeyPresses(str) {
for(var i = 0; i < str.length; i++) {
sendKeyPress(str.charCodeAt(i));
}
}

function sendKeyPress(charCode, eventProps) {
var input = getInput();
var event = jQuery.Event('keypress', { charCode: charCode });
var event = jQuery.Event('keypress', jQuery.extend({}, eventProps||{}, { charCode: charCode }));

input.trigger(event);
if (!event.isDefaultPrevented()) {
Expand Down Expand Up @@ -964,4 +968,20 @@ describe('tags-input-directive', function() {
expect(autocompleteObj.getTags()).toEqual(['a', 'b', 'c']);
});
});
});

describe('key presses with modifiers do not trigger hotkeys', function() {
it('allows shift-comma to enter a left angle character', function() {
// Arrange
compile('add-on-comma="true"');

// Act
sendKeyPresses('Testing ');
sendKeyPress(',', {shiftKey: true});
sendKeyPresses('test>');
sendKeyDown(KEYS.comma);

// Assert
expect($scope.tags).toEqual(['Testing <test>']);
});
});
});