Skip to content
Merged
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
21 changes: 21 additions & 0 deletions asset/js/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(function (root, factory) {
"use strict";

if (typeof define === "function" && define.icinga) {
define(["exports"], factory);
} else {
factory(root.iplWebFunctions = root.iplWebFunctions || {});
}
}(self, function (exports) {
/**
* Checks if the given keyboard event represents a special key press.
*
* @param {KeyboardEvent} event - The keyboard event to check.
* @returns {boolean} True if the event represents a special key press, false otherwise.
*/
function isSpecialKeyPress(event) {
return event.key.length > 1 || event.ctrlKey || event.metaKey;
Comment thread
sukhwinder33445 marked this conversation as resolved.
}

exports.isSpecialKeyPress = isSpecialKeyPress;
}));
4 changes: 2 additions & 2 deletions asset/js/widget/BaseInput.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["../notjQuery", "Completer"], function ($, Completer) {
define(["../notjQuery", "../functions", "Completer"], function ($, functions, Completer) {

"use strict";

Expand Down Expand Up @@ -803,7 +803,7 @@ define(["../notjQuery", "Completer"], function ($, Completer) {
let input = event.target;
let termIndex = Number(input.parentNode.dataset.index);

if (this.hasSyntaxError(input) && ! (/[A-Z]/.test(event.key.charAt(0)) || event.ctrlKey || event.metaKey)) {
if (this.hasSyntaxError(input) && ! functions.isSpecialKeyPress(event)) {
// Clear syntax error flag if the user types entirely new input after having selected the entire input
// (This way the input isn't empty but switches from input to input immediately, causing the clearing
// in onInput to not work)
Expand Down
12 changes: 0 additions & 12 deletions asset/js/widget/Completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,18 +695,6 @@ define(["../notjQuery"], function ($) {
event.preventDefault();
this.moveToSuggestion();
}

break;
default:
if (/[A-Z]/.test(event.key.charAt(0)) || event.key === '"') {
// Ignore control keys not resulting in new input data
break;
}

let typedSuggestion = this.termSuggestions.querySelector(`[value="${ event.key }"]`);
if (typedSuggestion !== null) {
this.hideSuggestions();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions asset/js/widget/FilterInput.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["../notjQuery", "BaseInput"], function ($, BaseInput) {
define(["../notjQuery", "../functions", "BaseInput"], function ($, functions, BaseInput) {

"use strict";

Expand Down Expand Up @@ -1350,7 +1350,7 @@ define(["../notjQuery", "BaseInput"], function ($, BaseInput) {
} else if (input.selectionStart !== input.selectionEnd) {
// In case the user selected a range of text, do nothing
return;
} else if (/[A-Z]/.test(event.key.charAt(0)) || event.ctrlKey || event.metaKey) {
} else if (functions.isSpecialKeyPress(event)) {
// Ignore control keys not resulting in new input data
// TODO: Remove this and move the entire block into `onInput`
// once Safari supports `InputEvent.data`
Expand Down
Loading