add autocompletion extension from useMemo
This commit is contained in:
parent
8e6909478c
commit
5e09c3c318
1 changed files with 14 additions and 10 deletions
|
|
@ -133,20 +133,24 @@ export default function CodeMirror({
|
||||||
);
|
);
|
||||||
|
|
||||||
const extensions = useMemo(() => {
|
const extensions = useMemo(() => {
|
||||||
|
let _extensions = [...staticExtensions];
|
||||||
let bindings = {
|
let bindings = {
|
||||||
vim,
|
vim,
|
||||||
emacs,
|
emacs,
|
||||||
};
|
};
|
||||||
if (bindings[keybindings]) {
|
|
||||||
return [...staticExtensions, bindings[keybindings]()];
|
|
||||||
}
|
|
||||||
return staticExtensions;
|
|
||||||
}, [keybindings]);
|
|
||||||
|
|
||||||
const setAutoCompletion = (isAutoCompletionEnabled) =>
|
if (bindings[keybindings]) {
|
||||||
isAutoCompletionEnabled
|
_extensions.push(bindings[keybindings]());
|
||||||
? javascriptLanguage.data.of({ autocomplete: strudelAutocomplete })
|
}
|
||||||
: autocompletion({ override: [] });
|
|
||||||
|
if (isAutoCompletionEnabled) {
|
||||||
|
_extensions.push(javascriptLanguage.data.of({ autocomplete: strudelAutocomplete }));
|
||||||
|
} else {
|
||||||
|
_extensions.push(autocompletion({ override: [] }));
|
||||||
|
}
|
||||||
|
|
||||||
|
return _extensions;
|
||||||
|
}, [keybindings, isAutoCompletionEnabled]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ fontSize, fontFamily }} className="w-full">
|
<div style={{ fontSize, fontFamily }} className="w-full">
|
||||||
|
|
@ -156,7 +160,7 @@ export default function CodeMirror({
|
||||||
onChange={handleOnChange}
|
onChange={handleOnChange}
|
||||||
onCreateEditor={handleOnCreateEditor}
|
onCreateEditor={handleOnCreateEditor}
|
||||||
onUpdate={handleOnUpdate}
|
onUpdate={handleOnUpdate}
|
||||||
extensions={[...extensions, setAutoCompletion(isAutoCompletionEnabled)]}
|
extensions={extensions}
|
||||||
basicSetup={{ lineNumbers: isLineNumbersDisplayed }}
|
basicSetup={{ lineNumbers: isLineNumbersDisplayed }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue