Skip to content

Commit 8f09fbf

Browse files
author
Ian Prest
committed
Fix a problem where you couldn't type a question-mark
-- For some reason, showHelp() was no longer able to detect which element had raised the event when you typed a question-mark, so the help dialog would pop up when you were trying to edit a legend. -- Fixed by consulting document.activeElement instead of the event's srcElement -- Also added some unit tests for this.
1 parent 66b278b commit 8f09fbf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

kb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@
863863
};
864864

865865
$scope.showHelp = function(event) {
866-
if(!event.srcElement || (event.srcElement.nodeName !== "INPUT" && event.srcElement.nodeName !== "TEXTAREA")) {
866+
if(!document.activeElement || (document.activeElement.nodeName !== "INPUT" && document.activeElement.nodeName !== "TEXTAREA")) {
867867
if(activeModal) activeModal.dismiss('cancel');
868868
activeModal = $modal.open({
869869
templateUrl:"helpDialog.html",

tests/kb-spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,33 @@ describe('keyboard-layout-editor', function() {
1515
capture.snap(getSpecName(), $('#keyboard'));
1616
};
1717

18+
beforeEach(function() {
19+
// Hacky workaround to prevent alert dialogs from breaking all the tests
20+
browser.executeScript("window.onbeforeunload = function(){};");
21+
});
22+
1823
// Simple launch test
1924
it('should launch without an error', function() {
2025
browser.get('');
2126
kbScreenshot();
2227
});
2328

29+
describe('show-help', function() {
30+
it('should appear I press "?"', function() {
31+
browser.get('');
32+
element(by.css('body')).sendKeys('?'); // try to type a question-mark
33+
expect(element(by.css('.modal-dialog')).isPresent()).toBeTruthy();
34+
});
35+
36+
it('should not appear when I press "?" in an edit field', function() {
37+
browser.get('');
38+
element(by.id('keyboard')).sendKeys('j'); // select a key
39+
element(by.id('labeleditor0')).sendKeys('?'); // try to type a question-mark
40+
expect(element(by.css('.modal-dialog')).isPresent()).toBeFalsy();
41+
expect(element(by.id('labeleditor0')).getAttribute('value')).toContain('?');
42+
});
43+
});
44+
2445
// Test renderings of various samples
2546
describe('rendering sample', function() {
2647
it('commodore-vic20', function() {

0 commit comments

Comments
 (0)