add minimum requirement of 2 [A-za-z] for slashcommand autocomplete to show up (#4080) * add minimum requirement of 2 [A-za-z] for slashcommand autocomplete to show up * Migrate to dedicated AC toggle * Replace state checkbox with select --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>

fa10833e520b2e39c6597308126a0d0276ca904d

RossAscends <124905043+RossAscends@users.noreply.github.com>

Signed
4 files changed, +31 -7Showing whitespace changes
public/index.html+8 -0
@@ -5041,6 +5041,14 @@
5041 <div class="fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>5041 <div class="fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>
5042 </div>5042 </div>
5043 <div class="inline-drawer-content">5043 <div class="inline-drawer-content">
5044 <label for="stscript_autocomplete_state">
5045 <small data-i18n="Visibility">Visibility</small>
5046 </label>
5047 <select id="stscript_autocomplete_state">
5048 <option value="0" data-i18n="Don't show">Don't show</option>
5049 <option value="1" data-i18n="Input length > 1">Input length > 1</option>
5050 <option value="2" data-i18n="Always show">Always show</option>
5051 </select>
5044 <label class="checkbox_label" for="stscript_autocomplete_autoHide">5052 <label class="checkbox_label" for="stscript_autocomplete_autoHide">
5045 <input id="stscript_autocomplete_autoHide" type="checkbox" />5053 <input id="stscript_autocomplete_autoHide" type="checkbox" />
5046 <small data-i18n="Automatically hide details">5054 <small data-i18n="Automatically hide details">
public/scripts/autocomplete/AutoComplete.js+10 -4
@@ -21,6 +21,14 @@ export const AUTOCOMPLETE_SELECT_KEY = {
21 'ENTER': 2, // 2^121 'ENTER': 2, // 2^1
22};22};
2323
24/** @readonly */
25/** @enum {Number} */
26export const AUTOCOMPLETE_STATE = {
27 DISABLED: 0,
28 MIN_LENGTH: 1,
29 ALWAYS: 2,
30};
31
24export class AutoComplete {32export class AutoComplete {
25 /**@type {HTMLTextAreaElement|HTMLInputElement}*/ textarea;33 /**@type {HTMLTextAreaElement|HTMLInputElement}*/ textarea;
26 /**@type {boolean}*/ isFloating = false;34 /**@type {boolean}*/ isFloating = false;
@@ -254,8 +262,7 @@ export class AutoComplete {
254 + this.parserResult.name.length262 + this.parserResult.name.length
255 + (this.startQuote ? 1 : 0)263 + (this.startQuote ? 1 : 0)
256 + (this.endQuote ? 1 : 0)264 + (this.endQuote ? 1 : 0)
257 + 1265 + 1;
258 ;
259 }266 }
260267
261 /**268 /**
@@ -387,8 +394,7 @@ export class AutoComplete {
387 return option;394 return option;
388 })395 })
389 // sort by fuzzy score or alphabetical396 // sort by fuzzy score or alphabetical
390 .toSorted(this.matchType == 'fuzzy' ? this.fuzzyScoreCompare : (a, b) => a.name.localeCompare(b.name))397 .toSorted(this.matchType == 'fuzzy' ? this.fuzzyScoreCompare : (a, b) => a.name.localeCompare(b.name));
391 ;
392398
393399
394400
public/scripts/power-user.js+11 -1
@@ -49,7 +49,7 @@ import { FILTER_TYPES } from './filters.js';
49import { PARSER_FLAG, SlashCommandParser } from './slash-commands/SlashCommandParser.js';49import { PARSER_FLAG, SlashCommandParser } from './slash-commands/SlashCommandParser.js';
50import { SlashCommand } from './slash-commands/SlashCommand.js';50import { SlashCommand } from './slash-commands/SlashCommand.js';
51import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';51import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
52import { AUTOCOMPLETE_SELECT_KEY, AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js';52import { AUTOCOMPLETE_SELECT_KEY, AUTOCOMPLETE_STATE, AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js';
53import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';53import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';
54import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';54import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
55import { POPUP_TYPE, callGenericPopup, fixToastrForDialogs } from './popup.js';55import { POPUP_TYPE, callGenericPopup, fixToastrForDialogs } from './popup.js';
@@ -306,6 +306,7 @@ let power_user = {
306 stscript: {306 stscript: {
307 matching: 'fuzzy',307 matching: 'fuzzy',
308 autocomplete: {308 autocomplete: {
309 state: AUTOCOMPLETE_STATE.ALWAYS,
309 autoHide: false,310 autoHide: false,
310 style: 'theme',311 style: 'theme',
311 font: {312 font: {
@@ -1505,6 +1506,9 @@ async function loadPowerUserSettings(settings, data) {
1505 if (power_user.stscript.autocomplete === undefined) {1506 if (power_user.stscript.autocomplete === undefined) {
1506 power_user.stscript.autocomplete = defaultStscript.autocomplete;1507 power_user.stscript.autocomplete = defaultStscript.autocomplete;
1507 } else {1508 } else {
1509 if (power_user.stscript.autocomplete.state === undefined) {
1510 power_user.stscript.autocomplete.state = defaultStscript.autocomplete.state;
1511 }
1508 if (power_user.stscript.autocomplete.width === undefined) {1512 if (power_user.stscript.autocomplete.width === undefined) {
1509 power_user.stscript.autocomplete.width = defaultStscript.autocomplete.width;1513 power_user.stscript.autocomplete.width = defaultStscript.autocomplete.width;
1510 }1514 }
@@ -1642,6 +1646,7 @@ async function loadPowerUserSettings(settings, data) {
1642 $('#aux_field').val(power_user.aux_field);1646 $('#aux_field').val(power_user.aux_field);
1643 $('#tag_import_setting').val(power_user.tag_import_setting);1647 $('#tag_import_setting').val(power_user.tag_import_setting);
16441648
1649 $('#stscript_autocomplete_state').val(power_user.stscript.autocomplete.state).trigger('input');
1645 $('#stscript_autocomplete_autoHide').prop('checked', power_user.stscript.autocomplete.autoHide ?? false).trigger('input');1650 $('#stscript_autocomplete_autoHide').prop('checked', power_user.stscript.autocomplete.autoHide ?? false).trigger('input');
1646 $('#stscript_matching').val(power_user.stscript.matching ?? 'fuzzy');1651 $('#stscript_matching').val(power_user.stscript.matching ?? 'fuzzy');
1647 $('#stscript_autocomplete_style').val(power_user.stscript.autocomplete.style ?? 'theme');1652 $('#stscript_autocomplete_style').val(power_user.stscript.autocomplete.style ?? 'theme');
@@ -3871,6 +3876,11 @@ $(document).ready(() => {
3871 saveSettingsDebounced();3876 saveSettingsDebounced();
3872 });3877 });
38733878
3879 $('#stscript_autocomplete_state').on('input', function () {
3880 power_user.stscript.autocomplete.state = Number($(this).val());
3881 saveSettingsDebounced();
3882 });
3883
3874 $('#stscript_autocomplete_autoHide').on('input', function () {3884 $('#stscript_autocomplete_autoHide').on('input', function () {
3875 power_user.stscript.autocomplete.autoHide = !!$(this).prop('checked');3885 power_user.stscript.autocomplete.autoHide = !!$(this).prop('checked');
3876 saveSettingsDebounced();3886 saveSettingsDebounced();
public/scripts/slash-commands.js+2 -2
@@ -67,7 +67,7 @@ import { background_settings } from './backgrounds.js';
67import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';67import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';
68import { SlashCommandClosureResult } from './slash-commands/SlashCommandClosureResult.js';68import { SlashCommandClosureResult } from './slash-commands/SlashCommandClosureResult.js';
69import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';69import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
70import { AutoComplete } from './autocomplete/AutoComplete.js';70import { AutoComplete, AUTOCOMPLETE_STATE } from './autocomplete/AutoComplete.js';
71import { SlashCommand } from './slash-commands/SlashCommand.js';71import { SlashCommand } from './slash-commands/SlashCommand.js';
72import { SlashCommandAbortController } from './slash-commands/SlashCommandAbortController.js';72import { SlashCommandAbortController } from './slash-commands/SlashCommandAbortController.js';
73import { SlashCommandNamedArgumentAssignment } from './slash-commands/SlashCommandNamedArgumentAssignment.js';73import { SlashCommandNamedArgumentAssignment } from './slash-commands/SlashCommandNamedArgumentAssignment.js';
@@ -4927,7 +4927,7 @@ export async function setSlashCommandAutoComplete(textarea, isFloating = false)
4927 const parser = new SlashCommandParser();4927 const parser = new SlashCommandParser();
4928 const ac = new AutoComplete(4928 const ac = new AutoComplete(
4929 textarea,4929 textarea,
4930 () => ac.text[0] == '/',4930 () => ac.text[0] == '/' && (power_user.stscript.autocomplete.state === AUTOCOMPLETE_STATE.ALWAYS || power_user.stscript.autocomplete.state === AUTOCOMPLETE_STATE.MIN_LENGTH && ac.text.length > 2),
4931 async (text, index) => await parser.getNameAt(text, index),4931 async (text, index) => await parser.getNameAt(text, index),
4932 isFloating,4932 isFloating,
4933 );4933 );