Skip to content

Commit

Permalink
removed redundant effect
Browse files Browse the repository at this point in the history
  • Loading branch information
arausly committed Nov 26, 2024
1 parent edbb7b6 commit 16496c3
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions src/components/AutoSuggestion/AutoSuggestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,9 @@ const AutoSuggestion = ({
}, [cm, editorState]);

const dispatch = // eslint-disable-next-line @typescript-eslint/no-empty-function
(typeof editorState?.cm?.dispatch === "function" ? editorState?.cm?.dispatch : () => {}) as EditorView["dispatch"];

React.useEffect(() => {
if (initialValue != null && cm) {
dispatch({
changes: { from: 0, to: cm?.state?.doc.length, insert: initialValue },
});
}
}, [initialValue, cm]);
(
typeof editorState?.cm?.dispatch === "function" ? editorState?.cm?.dispatch : () => {}
) as EditorView["dispatch"];

React.useEffect(() => {
editorState.dropdownShown = shouldShowDropdown;
Expand Down Expand Up @@ -610,23 +604,34 @@ const AutoSuggestion = ({
);

const codeEditor = React.useMemo(() => {
return <ExtendedCodeEditor
mode={mode}
setCM={setCM}
onChange={handleChange}
onCursorChange={handleCursorChange}
initialValue={initialValue}
onFocusChange={handleInputFocus}
onKeyDown={handleInputEditorKeyPress}
enableTab={useTabForCompletions}
placeholder={placeholder}
onSelection={onSelection}
showScrollBar={showScrollBar}
multiline={multiline}
onMouseDown={handleInputMouseDown}
/>

}, [mode, setCM, handleChange, initialValue, useTabForCompletions, placeholder, showScrollBar, multiline, handleInputMouseDown])
return (
<ExtendedCodeEditor
mode={mode}
setCM={setCM}
onChange={handleChange}
onCursorChange={handleCursorChange}
initialValue={initialValue}
onFocusChange={handleInputFocus}
onKeyDown={handleInputEditorKeyPress}
enableTab={useTabForCompletions}
placeholder={placeholder}
onSelection={onSelection}
showScrollBar={showScrollBar}
multiline={multiline}
onMouseDown={handleInputMouseDown}
/>
);
}, [
mode,
setCM,
handleChange,
initialValue,
useTabForCompletions,
placeholder,
showScrollBar,
multiline,
handleInputMouseDown,
]);

const hasError = !!value.current && !pathIsValid && !pathValidationPending;
const autoSuggestionInput = (
Expand Down

0 comments on commit 16496c3

Please sign in to comment.