Skip to content

Commit f2cdc09

Browse files
authored
Merge pull request #1887 from emergie/bugfix_#1810_Keyboard_shortcuts_are_active_when_typing_into_search_box
bugfix: #1810 Keyboard shortcuts are active when typing into search b…
2 parents b795f27 + 0912288 commit f2cdc09

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

web/js/diff-0.0.2.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* CDDL HEADER END
1818
*/
1919

20+
/* global textInputHasFocus */
21+
2022
/*
2123
* Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved.
2224
*/
@@ -124,6 +126,9 @@
124126
load: function ($window) {
125127
var that = this
126128
$(document).keypress(function (e) {
129+
if (textInputHasFocus()) {
130+
return true;
131+
}
127132
var key = e.keyCode || e.which
128133
switch (key) {
129134
case 110: // n

web/js/utils-0.0.18.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,9 @@
846846
load: function ($window) {
847847
var that = this;
848848
$(document).keypress(function (e) {
849+
if (textInputHasFocus()) {
850+
return true;
851+
}
849852
var key = e.which;
850853
switch (key) {
851854
case 49: // 1
@@ -1953,13 +1956,14 @@ function isOnSearchPage() {
19531956
*/
19541957
function searchSubmit(form) {
19551958
var submitInitiator = '';
1956-
if (document.activeElement && document.activeElement.nodeName === 'INPUT') {
1959+
if (textInputHasFocus()) {
19571960
submitInitiator = document.activeElement.getAttribute('id');
19581961
}
19591962
if (submitInitiator) {
19601963
var input = document.createElement('INPUT');
19611964
input.setAttribute('name', 'si');
19621965
input.value = submitInitiator;
1966+
input.type = 'hidden';
19631967
form.appendChild(input);
19641968
}
19651969
}
@@ -1980,3 +1984,12 @@ function restoreFocusAfterSearchSubmit() {
19801984
}
19811985
}
19821986
}
1987+
1988+
/**
1989+
* @return {boolean} true if focus is on a input[type=text] element
1990+
*/
1991+
function textInputHasFocus() {
1992+
return !!document.activeElement &&
1993+
document.activeElement.nodeName === 'INPUT' &&
1994+
document.activeElement.type === 'text';
1995+
}

0 commit comments

Comments
 (0)