Refactor regex info block to use a shared function
| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | </small> |
| 17 | 17 | <hr /> |
| 18 | 18 | |
| 19 | 19 | <div id="regex_info_block" class="info-blockregex_info_block_wrapper"> |
| 20 | 20 | <spandiv id="regex_info_block" class="info-block-text"></spandiv> |
| 21 | 21 | <a classid="info-block-flags-hintregex_info_block_flags_hint" href="http://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags" target="_blank" rel="noopener noreferrer"> |
| 22 | 22 | <i class="fa-solid fa-circle-info" title="Click here to learn more about regex flags."></i> |
| 23 | 23 | </a> |
| 24 | 24 | </div> |
| @@ -7,7 +7,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from ' | ||
| 7 | 7 | import { enumIcons } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 8 | 8 | import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js'; |
| 9 | 9 | import { SlashCommandParser } from '../../slash-commands/SlashCommandParser.js'; |
| 10 | 10 | import { download, getFileText, getSortableDelay, regexFromString, setInfoBlock, uuidv4 } from '../../utils.js'; |
| 11 | 11 | import { regex_placement, runRegexScript, substitute_find_regex } from './engine.js'; |
| 12 | 12 | import { t } from '../../i18n.js'; |
| 13 | 13 | import { accountStorage } from '../../util/AccountStorage.js'; |
| @@ -313,18 +313,15 @@ async function onRegexEditorOpenClick(existingId, isScoped) { | ||
| 313 | 313 | * @param {JQuery<HTMLElement>} editorHtml The editor HTML |
| 314 | 314 | */ |
| 315 | 315 | function updateInfoBlock(editorHtml) { |
| 316 | 316 | const infoBlock = editorHtml.find('.info-block').get(0); |
| 317 | 317 | const infoBlockTextSpaninfoBlockFlagsHint = infoBlockeditorHtml.find('.info-block-text#regex_info_block_flags_hint'); |
| 318 | - const infoBlockFlagsHint = infoBlock.find('.info-block-flags-hint'); | |
| 319 | 318 | const findRegex = String(editorHtml.find('.find_regex').val()); |
| 320 | 319 | |
| 321 | - infoBlock.removeClass('error hint info warning'); | |
| 322 | 320 | infoBlockFlagsHint.hide(); |
| 323 | 321 | |
| 324 | 322 | // Clear the info block if the find regex is empty |
| 325 | 323 | if (!findRegex) { |
| 326 | - infoBlock.addClass('info'); | |
| 324 | + setInfoBlock(infoBlock, t`Find Regex is empty`, 'info'); | |
| 327 | - infoBlockTextSpan.text(t`Find Regex is empty`); | |
| 328 | 325 | return; |
| 329 | 326 | } |
| 330 | 327 | |
| @@ -338,12 +335,10 @@ function updateInfoBlock(editorHtml) { | ||
| 338 | 335 | flagInfo.push(regex.flags.includes('g') ? t`Applies to all matches` : t`Applies to the first match`); |
| 339 | 336 | flagInfo.push(regex.flags.includes('i') ? t`Case insensitive` : t`Case sensitive`); |
| 340 | 337 | |
| 341 | 338 | setInfoBlock(infoBlock, flagInfo.addClassjoin('. '), 'hint'); |
| 342 | - infoBlockTextSpan.text(flagInfo.join('. ')); | |
| 343 | 339 | infoBlockFlagsHint.show(); |
| 344 | 340 | } catch (error) { |
| 345 | 341 | setInfoBlock(infoBlock, error.addClass(message, 'error'); |
| 346 | - infoBlockTextSpan.text(error.message); | |
| 347 | 342 | } |
| 348 | 343 | } |
| 349 | 344 | |
| @@ -106,18 +106,21 @@ input.enable_scoped { | ||
| 106 | 106 | display: block; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | #regex_info_blockregex_info_block_wrapper { |
| 110 | 110 | position: relative; |
| 111 | +} | |
| 112 | + | |
| 113 | +#regex_info_block { | |
| 111 | 114 | margin: 10px 0; |
| 112 | 115 | padding: 5px 20px; |
| 113 | 116 | font-size: 0.9em; |
| 114 | 117 | } |
| 115 | 118 | |
| 116 | 119 | #regex_info_block_wrapper:has(#regex_info_block:empty) { |
| 117 | 120 | display: none; |
| 118 | 121 | } |
| 119 | 122 | |
| 120 | -#regex_info_block .info-block-flags-hint { | |
| 123 | +#regex_info_block_flags_hint { | |
| 121 | 124 | position: absolute; |
| 122 | 125 | top: 50%; |
| 123 | 126 | right: 10px; |