Compare commits

..

4 Commits

Author SHA1 Message Date
LenAnderson 38e468dc4f restore selection on non-replace select 2024-04-17 09:02:37 -04:00
LenAnderson ed01e94c9f re-enable blur listener 2024-04-17 09:02:21 -04:00
LenAnderson 04fca9f370 fix options filter 2024-04-17 09:02:10 -04:00
LenAnderson 10e786dfd3 don't run parser for getNameAt if text has not changed 2024-04-17 09:01:41 -04:00
2 changed files with 16 additions and 7 deletions

View File

@ -2067,7 +2067,7 @@ export async function setSlashCommandAutoComplete(textarea, isFloating = false)
else { else {
let matchingOptions = parserResult.optionList let matchingOptions = parserResult.optionList
.filter(it => isReplacable || it.name == '' ? matchers[matchType](it.name) : it.name.toLowerCase() == slashCommand) // Filter by the input .filter(it => isReplacable || it.name == '' ? matchers[matchType](it.name) : it.name.toLowerCase() == slashCommand) // Filter by the input
.filter((it,idx,list) => list.indexOf(it) == idx) .filter((it,idx,list) => list.findIndex(opt=>opt.value == it.value) == idx)
; ;
result = matchingOptions result = matchingOptions
.filter((it,idx) => matchingOptions.indexOf(it) == idx) .filter((it,idx) => matchingOptions.indexOf(it) == idx)
@ -2266,6 +2266,13 @@ export async function setSlashCommandAutoComplete(textarea, isFloating = false)
textarea.selectionStart = parserResult.start - 2 + selectedItem.replacer.length; textarea.selectionStart = parserResult.start - 2 + selectedItem.replacer.length;
textarea.selectionEnd = textarea.selectionStart; textarea.selectionEnd = textarea.selectionStart;
show(); show();
} else {
const selectionStart = textarea.selectionStart;
const selectionEnd = textarea.selectionDirection;
await pointerup;
textarea.focus();
textarea.selectionStart = selectionStart;
textarea.selectionDirection = selectionEnd;
} }
}; };
const showAutoCompleteDebounced = show; const showAutoCompleteDebounced = show;
@ -2381,7 +2388,7 @@ export async function setSlashCommandAutoComplete(textarea, isFloating = false)
} }
} }
}); });
// textarea.addEventListener('blur', ()=>hide()); textarea.addEventListener('blur', ()=>hide());
if (isFloating) { if (isFloating) {
textarea.addEventListener('scroll', debounce(updateFloatingPosition, 100)); textarea.addEventListener('scroll', debounce(updateFloatingPosition, 100));
} }

View File

@ -178,11 +178,13 @@ export class SlashCommandParser {
* @param {*} index Index to check for names (cursor position). * @param {*} index Index to check for names (cursor position).
*/ */
getNameAt(text, index) { getNameAt(text, index) {
try { if (this.text != `{:${text}:}`) {
this.parse(text, false); try {
} catch (e) { this.parse(text, false);
// do nothing } catch (e) {
console.warn(e); // do nothing
console.warn(e);
}
} }
index += 2; index += 2;
const executor = this.commandIndex const executor = this.commandIndex