Improve slashCommand autoCompletion logic (#2776)
This commit is contained in:
parent
8957ad7fc3
commit
383306e17e
|
@ -113,7 +113,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const query = buffer.text;
|
const query = buffer.text;
|
||||||
const selectedSuggestion = completionSuggestions[indexToUse];
|
const suggestion = completionSuggestions[indexToUse].value;
|
||||||
|
|
||||||
if (query.trimStart().startsWith('/')) {
|
if (query.trimStart().startsWith('/')) {
|
||||||
const parts = query.trimStart().substring(1).split(' ');
|
const parts = query.trimStart().substring(1).split(' ');
|
||||||
|
@ -122,11 +122,16 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||||
const base = query.substring(0, slashIndex + 1);
|
const base = query.substring(0, slashIndex + 1);
|
||||||
|
|
||||||
const command = slashCommands.find((cmd) => cmd.name === commandName);
|
const command = slashCommands.find((cmd) => cmd.name === commandName);
|
||||||
if (command && command.completion) {
|
// Make sure completion isn't the original command when command.completigion hasn't happened yet.
|
||||||
const newValue = `${base}${commandName} ${selectedSuggestion.value}`;
|
if (command && command.completion && suggestion !== commandName) {
|
||||||
buffer.setText(newValue);
|
const newValue = `${base}${commandName} ${suggestion}`;
|
||||||
|
if (newValue === query) {
|
||||||
|
handleSubmitAndClear(newValue);
|
||||||
} else {
|
} else {
|
||||||
const newValue = base + selectedSuggestion.value;
|
buffer.setText(newValue);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const newValue = base + suggestion;
|
||||||
buffer.setText(newValue);
|
buffer.setText(newValue);
|
||||||
handleSubmitAndClear(newValue);
|
handleSubmitAndClear(newValue);
|
||||||
}
|
}
|
||||||
|
@ -142,7 +147,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
|
||||||
buffer.replaceRangeByOffset(
|
buffer.replaceRangeByOffset(
|
||||||
autoCompleteStartIndex,
|
autoCompleteStartIndex,
|
||||||
buffer.text.length,
|
buffer.text.length,
|
||||||
selectedSuggestion.value,
|
suggestion,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
resetCompletionState();
|
resetCompletionState();
|
||||||
|
|
|
@ -135,7 +135,8 @@ export function useCompletion(
|
||||||
(cmd) => cmd.name === commandName || cmd.altName === commandName,
|
(cmd) => cmd.name === commandName || cmd.altName === commandName,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (command && command.completion) {
|
// Continue to show command help until user types past command name.
|
||||||
|
if (command && command.completion && parts.length > 1) {
|
||||||
const fetchAndSetSuggestions = async () => {
|
const fetchAndSetSuggestions = async () => {
|
||||||
setIsLoadingSuggestions(true);
|
setIsLoadingSuggestions(true);
|
||||||
if (command.completion) {
|
if (command.completion) {
|
||||||
|
|
Loading…
Reference in New Issue