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>
This commit is contained in:
RossAscends
2025-06-02 02:07:33 +09:00
committed by GitHub
parent 4c3bb1aede
commit fa10833e52
4 changed files with 57 additions and 33 deletions

View File

@@ -5041,6 +5041,14 @@
<div class="fa-solid fa-circle-chevron-down inline-drawer-icon down"></div>
</div>
<div class="inline-drawer-content">
<label for="stscript_autocomplete_state">
<small data-i18n="Visibility">Visibility</small>
</label>
<select id="stscript_autocomplete_state">
<option value="0" data-i18n="Don't show">Don't show</option>
<option value="1" data-i18n="Input length > 1">Input length > 1</option>
<option value="2" data-i18n="Always show">Always show</option>
</select>
<label class="checkbox_label" for="stscript_autocomplete_autoHide">
<input id="stscript_autocomplete_autoHide" type="checkbox" />
<small data-i18n="Automatically hide details">

View File

@@ -21,6 +21,14 @@ export const AUTOCOMPLETE_SELECT_KEY = {
'ENTER': 2, // 2^1
};
/** @readonly */
/** @enum {Number} */
export const AUTOCOMPLETE_STATE = {
DISABLED: 0,
MIN_LENGTH: 1,
ALWAYS: 2,
};
export class AutoComplete {
/**@type {HTMLTextAreaElement|HTMLInputElement}*/ textarea;
/**@type {boolean}*/ isFloating = false;
@@ -254,8 +262,7 @@ export class AutoComplete {
+ this.parserResult.name.length
+ (this.startQuote ? 1 : 0)
+ (this.endQuote ? 1 : 0)
+ 1
;
+ 1;
}
/**
@@ -387,8 +394,7 @@ export class AutoComplete {
return option;
})
// sort by fuzzy score or alphabetical
.toSorted(this.matchType == 'fuzzy' ? this.fuzzyScoreCompare : (a, b) => a.name.localeCompare(b.name))
;
.toSorted(this.matchType == 'fuzzy' ? this.fuzzyScoreCompare : (a, b) => a.name.localeCompare(b.name));

View File

@@ -49,7 +49,7 @@ import { FILTER_TYPES } from './filters.js';
import { PARSER_FLAG, SlashCommandParser } from './slash-commands/SlashCommandParser.js';
import { SlashCommand } from './slash-commands/SlashCommand.js';
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
import { AUTOCOMPLETE_SELECT_KEY, AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js';
import { AUTOCOMPLETE_SELECT_KEY, AUTOCOMPLETE_STATE, AUTOCOMPLETE_WIDTH } from './autocomplete/AutoComplete.js';
import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';
import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
import { POPUP_TYPE, callGenericPopup, fixToastrForDialogs } from './popup.js';
@@ -306,6 +306,7 @@ let power_user = {
stscript: {
matching: 'fuzzy',
autocomplete: {
state: AUTOCOMPLETE_STATE.ALWAYS,
autoHide: false,
style: 'theme',
font: {
@@ -1505,6 +1506,9 @@ async function loadPowerUserSettings(settings, data) {
if (power_user.stscript.autocomplete === undefined) {
power_user.stscript.autocomplete = defaultStscript.autocomplete;
} else {
if (power_user.stscript.autocomplete.state === undefined) {
power_user.stscript.autocomplete.state = defaultStscript.autocomplete.state;
}
if (power_user.stscript.autocomplete.width === undefined) {
power_user.stscript.autocomplete.width = defaultStscript.autocomplete.width;
}
@@ -1642,6 +1646,7 @@ async function loadPowerUserSettings(settings, data) {
$('#aux_field').val(power_user.aux_field);
$('#tag_import_setting').val(power_user.tag_import_setting);
$('#stscript_autocomplete_state').val(power_user.stscript.autocomplete.state).trigger('input');
$('#stscript_autocomplete_autoHide').prop('checked', power_user.stscript.autocomplete.autoHide ?? false).trigger('input');
$('#stscript_matching').val(power_user.stscript.matching ?? 'fuzzy');
$('#stscript_autocomplete_style').val(power_user.stscript.autocomplete.style ?? 'theme');
@@ -3871,6 +3876,11 @@ $(document).ready(() => {
saveSettingsDebounced();
});
$('#stscript_autocomplete_state').on('input', function () {
power_user.stscript.autocomplete.state = Number($(this).val());
saveSettingsDebounced();
});
$('#stscript_autocomplete_autoHide').on('input', function () {
power_user.stscript.autocomplete.autoHide = !!$(this).prop('checked');
saveSettingsDebounced();

View File

@@ -67,7 +67,7 @@ import { background_settings } from './backgrounds.js';
import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';
import { SlashCommandClosureResult } from './slash-commands/SlashCommandClosureResult.js';
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
import { AutoComplete } from './autocomplete/AutoComplete.js';
import { AutoComplete, AUTOCOMPLETE_STATE } from './autocomplete/AutoComplete.js';
import { SlashCommand } from './slash-commands/SlashCommand.js';
import { SlashCommandAbortController } from './slash-commands/SlashCommandAbortController.js';
import { SlashCommandNamedArgumentAssignment } from './slash-commands/SlashCommandNamedArgumentAssignment.js';
@@ -4927,7 +4927,7 @@ export async function setSlashCommandAutoComplete(textarea, isFloating = false)
const parser = new SlashCommandParser();
const ac = new AutoComplete(
textarea,
() => ac.text[0] == '/',
() => ac.text[0] == '/' && (power_user.stscript.autocomplete.state === AUTOCOMPLETE_STATE.ALWAYS || power_user.stscript.autocomplete.state === AUTOCOMPLETE_STATE.MIN_LENGTH && ac.text.length > 2),
async (text, index) => await parser.getNameAt(text, index),
isFloating,
);