diff --git a/package-lock.json b/package-lock.json index 8295e72..4f2d544 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@material/mwc-icon": "0.25.3", + "escape-string-regexp": "5.0.0", "hotkeys-js": "3.8.7", "lit": "2.2.6" }, @@ -2593,12 +2594,11 @@ "dev": true }, "node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", + "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", "engines": { - "node": ">=10" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -2710,6 +2710,18 @@ "@babel/highlight": "^7.10.4" } }, + "node_modules/eslint/node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/eslint/node_modules/eslint-utils": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", @@ -9826,10 +9838,9 @@ "dev": true }, "escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", + "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==" }, "eslint": { "version": "7.32.0", @@ -9888,6 +9899,12 @@ "@babel/highlight": "^7.10.4" } }, + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, "eslint-utils": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", diff --git a/package.json b/package.json index 190ec0f..094a7a5 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ }, "dependencies": { "@material/mwc-icon": "0.25.3", + "escape-string-regexp": "5.0.0", "hotkeys-js": "3.8.7", "lit": "2.2.6" }, diff --git a/src/ninja-keys.ts b/src/ninja-keys.ts index f473dac..15b6711 100644 --- a/src/ninja-keys.ts +++ b/src/ninja-keys.ts @@ -1,3 +1,4 @@ +import escapeStringRegexp from 'escape-string-regexp'; import {LitElement, html, TemplateResult, PropertyValues} from 'lit'; import {customElement, property, state} from 'lit/decorators.js'; import {repeat} from 'lit/directives/repeat.js'; @@ -304,31 +305,30 @@ export class NinjaKeys extends LitElement { private _unregisterInternalHotkeys() { if (this.openHotkey) { - hotkeys.unbind(this.openHotkey) + hotkeys.unbind(this.openHotkey); } if (this.selectHotkey) { - hotkeys.unbind(this.selectHotkey) + hotkeys.unbind(this.selectHotkey); } if (this.goBackHotkey) { - hotkeys.unbind(this.goBackHotkey) + hotkeys.unbind(this.goBackHotkey); } if (this.navigationDownHotkey) { - hotkeys.unbind(this.navigationDownHotkey) + hotkeys.unbind(this.navigationDownHotkey); } if (this.navigationUpHotkey) { - hotkeys.unbind(this.navigationUpHotkey) + hotkeys.unbind(this.navigationUpHotkey); } if (this.closeHotkey) { - hotkeys.unbind(this.closeHotkey) + hotkeys.unbind(this.closeHotkey); } } - private _actionFocused(index: INinjaAction, $event: MouseEvent) { // this.selectedIndex = index; this._selected = index; @@ -361,7 +361,8 @@ export class NinjaKeys extends LitElement { }; const actionMatches = this._flatData.filter((action) => { - const regex = new RegExp(this._search, 'gi'); + const escaped = escapeStringRegexp(this._search); + const regex = new RegExp(escaped, 'gi'); const matcher = action.title.match(regex) || action.keywords?.match(regex);