aboutsummaryrefslogtreecommitdiff
path: root/src/console
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2022-05-05 10:17:20 +0000
committerShin'ya Ueoka <ueokande@i-beam.org>2022-05-05 10:17:20 +0000
commitcc427e967d63523b90ecc1c6aa2c864cb13b4b58 (patch)
tree43ddaf5b2e0798d4656bbc1bdbaa1ae881283573 /src/console
parent0d17912972de6b9e8b08aedf141260413c60d7fd (diff)
Pass source string via argument
Diffstat (limited to 'src/console')
-rw-r--r--src/console/completion/hooks.ts17
-rw-r--r--src/console/components/CommandPrompt.tsx6
2 files changed, 7 insertions, 16 deletions
diff --git a/src/console/completion/hooks.ts b/src/console/completion/hooks.ts
index 3a2ec33..a2e8bde 100644
--- a/src/console/completion/hooks.ts
+++ b/src/console/completion/hooks.ts
@@ -170,16 +170,12 @@ export const getPropertyCompletions = async (
return [{ name: "Properties", items }];
};
-export const useCompletions = () => {
+export const useCompletions = (source: string) => {
const state = React.useContext(CompletionStateContext);
const dispatch = React.useContext(CompletionDispatchContext);
const commandLineParser = React.useMemo(() => new CommandLineParser(), []);
const [completionTypes] = useGetCompletionTypes();
- const updateCompletions = React.useCallback((source: string) => {
- dispatch(actions.setCompletionSource(source));
- }, []);
-
const queryCompletions = React.useCallback(
(text: string, completionTypes: CompletionType[]) => {
const phase = commandLineParser.inputPhase(text);
@@ -233,16 +229,15 @@ export const useCompletions = () => {
);
React.useEffect(() => {
+ dispatch(actions.setCompletionSource(source));
+
if (typeof completionTypes === "undefined") {
return;
}
- queryCompletions(state.completionSource, completionTypes);
- }, [state.completionSource, completionTypes]);
+ queryCompletions(source, completionTypes);
+ }, [source, completionTypes]);
- return {
- completions: state.completions,
- updateCompletions,
- };
+ return { completions: state.completions };
};
export const useSelectCompletion = () => {
diff --git a/src/console/components/CommandPrompt.tsx b/src/console/components/CommandPrompt.tsx
index 0312fe4..89acf57 100644
--- a/src/console/components/CommandPrompt.tsx
+++ b/src/console/components/CommandPrompt.tsx
@@ -22,7 +22,7 @@ const CommandPromptInner: React.FC<Props> = ({ initialInputValue }) => {
const hide = useHide();
const [inputValue, setInputValue] = React.useState(initialInputValue);
const debouncedValue = useDebounce(inputValue, 100);
- const { completions, updateCompletions } = useCompletions();
+ const { completions } = useCompletions(debouncedValue);
const { select, currentValue, selectNext, selectPrev } =
useSelectCompletion();
const execCommand = useExecCommand();
@@ -83,10 +83,6 @@ const CommandPromptInner: React.FC<Props> = ({ initialInputValue }) => {
setInputValue(text);
};
- React.useEffect(() => {
- updateCompletions(debouncedValue);
- }, [debouncedValue]);
-
return (
<ConsoleWrapper>
<Completion