Unrelated linting
| @@ -1,5 +1,4 @@ | |||
| 1 | import { escapeRegex } from '../utils.js'; | 1 | import { escapeRegex } from '../utils.js'; |
| 2 | import { SlashCommand } from './SlashCommand.js'; | ||
| 3 | import { SlashCommandParser } from './SlashCommandParser.js'; | 2 | import { SlashCommandParser } from './SlashCommandParser.js'; |
| 4 | 3 | ||
| 5 | export class SlashCommandBrowser { | 4 | export class SlashCommandBrowser { |
| @@ -12,7 +11,7 @@ export class SlashCommandBrowser { | |||
| 12 | 11 | ||
| 13 | renderInto(parent) { | 12 | renderInto(parent) { |
| 14 | if (!this.dom) { | 13 | if (!this.dom) { |
| 15 | const queryRegex = /(?:(?:^|\s+)([^\s"][^\s]*?)(?:\s+|$))|(?:(?:^|\s+)"(.*?)(?:"|$)(?:\s+|$))/; | 14 | const queryRegex = /(?:^|\s+)([^\s"]\S*?)(?:\s+|$)|(?:^|\s+)"(.*?)(?:"|$)(?:\s+|$)/; |
| 16 | const root = document.createElement('div'); { | 15 | const root = document.createElement('div'); { |
| 17 | this.dom = root; | 16 | this.dom = root; |
| 18 | const search = document.createElement('div'); { | 17 | const search = document.createElement('div'); { |
| @@ -30,7 +29,7 @@ export class SlashCommandBrowser { | |||
| 30 | this.details?.remove(); | 29 | this.details?.remove(); |
| 31 | this.details = null; | 30 | this.details = null; |
| 32 | let query = inp.value.trim(); | 31 | let query = inp.value.trim(); |
| 33 | if (query.slice(-1) == '"' && !/(?:^|\s+)"/.test(query)) { | 32 | if (query.slice(-1) === '"' && !/(?:^|\s+)"/.test(query)) { |
| 34 | query = `"${query}`; | 33 | query = `"${query}`; |
| 35 | } | 34 | } |
| 36 | let fuzzyList = []; | 35 | let fuzzyList = []; |
| @@ -59,7 +58,7 @@ export class SlashCommandBrowser { | |||
| 59 | cmd.helpString, | 58 | cmd.helpString, |
| 60 | ]; | 59 | ]; |
| 61 | const find = ()=>targets.find(t=>(fuzzyList.find(f=>f.test(t)) ?? quotedList.find(q=>t.includes(q))) !== undefined) !== undefined; | 60 | const find = ()=>targets.find(t=>(fuzzyList.find(f=>f.test(t)) ?? quotedList.find(q=>t.includes(q))) !== undefined) !== undefined; |
| 62 | if (fuzzyList.length + quotedList.length == 0 || find()) { | 61 | if (fuzzyList.length + quotedList.length === 0 || find()) { |
| 63 | this.itemMap[cmd.name].classList.remove('isFiltered'); | 62 | this.itemMap[cmd.name].classList.remove('isFiltered'); |
| 64 | } else { | 63 | } else { |
| 65 | this.itemMap[cmd.name].classList.add('isFiltered'); | 64 | this.itemMap[cmd.name].classList.add('isFiltered'); |
| @@ -78,7 +77,7 @@ export class SlashCommandBrowser { | |||
| 78 | list.classList.add('autoComplete'); | 77 | list.classList.add('autoComplete'); |
| 79 | this.cmdList = Object | 78 | this.cmdList = Object |
| 80 | .keys(SlashCommandParser.commands) | 79 | .keys(SlashCommandParser.commands) |
| 81 | .filter(key => SlashCommandParser.commands[key].name == key) // exclude aliases | 80 | .filter(key => SlashCommandParser.commands[key].name === key) // exclude aliases |
| 82 | .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())) | 81 | .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase())) |
| 83 | .map(key => SlashCommandParser.commands[key]) | 82 | .map(key => SlashCommandParser.commands[key]) |
| 84 | ; | 83 | ; |
| @@ -97,7 +96,7 @@ export class SlashCommandBrowser { | |||
| 97 | } | 96 | } |
| 98 | } | 97 | } |
| 99 | } | 98 | } |
| 100 | if (this.details != details) { | 99 | if (this.details !== details) { |
| 101 | Array.from(list.querySelectorAll('.selected')).forEach(it=>it.classList.remove('selected')); | 100 | Array.from(list.querySelectorAll('.selected')).forEach(it=>it.classList.remove('selected')); |
| 102 | item.classList.add('selected'); | 101 | item.classList.add('selected'); |
| 103 | this.details?.remove(); | 102 | this.details?.remove(); |
| @@ -124,7 +123,7 @@ export class SlashCommandBrowser { | |||
| 124 | parent.append(this.dom); | 123 | parent.append(this.dom); |
| 125 | 124 | ||
| 126 | this.mo = new MutationObserver(muts=>{ | 125 | this.mo = new MutationObserver(muts=>{ |
| 127 | if (muts.find(mut=>Array.from(mut.removedNodes).find(it=>it == this.dom || it.contains(this.dom)))) { | 126 | if (muts.find(mut=>Array.from(mut.removedNodes).find(it=>it === this.dom || it.contains(this.dom)))) { |
| 128 | this.mo.disconnect(); | 127 | this.mo.disconnect(); |
| 129 | window.removeEventListener('keydown', boundHandler); | 128 | window.removeEventListener('keydown', boundHandler); |
| 130 | } | 129 | } |
| @@ -136,7 +135,7 @@ export class SlashCommandBrowser { | |||
| 136 | } | 135 | } |
| 137 | 136 | ||
| 138 | handleKeyDown(evt) { | 137 | handleKeyDown(evt) { |
| 139 | if (!evt.shiftKey && !evt.altKey && evt.ctrlKey && evt.key.toLowerCase() == 'f') { | 138 | if (!evt.shiftKey && !evt.altKey && evt.ctrlKey && evt.key.toLowerCase() === 'f') { |
| 140 | if (!this.dom.closest('body')) return; | 139 | if (!this.dom.closest('body')) return; |
| 141 | if (this.dom.closest('.mes') && !this.dom.closest('.last_mes')) return; | 140 | if (this.dom.closest('.mes') && !this.dom.closest('.last_mes')) return; |
| 142 | evt.preventDefault(); | 141 | evt.preventDefault(); |