Add option in settings to enable autocompletion
This commit is contained in:
parent
6f04a1b8fa
commit
2d2d0cabb3
4 changed files with 36 additions and 4 deletions
|
|
@ -103,6 +103,7 @@ export default function CodeMirror({
|
|||
theme,
|
||||
keybindings,
|
||||
isLineNumbersDisplayed,
|
||||
isAutoCompletionEnabled,
|
||||
fontSize = 18,
|
||||
fontFamily = 'monospace',
|
||||
options,
|
||||
|
|
@ -114,12 +115,14 @@ export default function CodeMirror({
|
|||
},
|
||||
[onChange],
|
||||
);
|
||||
|
||||
const handleOnCreateEditor = useCallback(
|
||||
(view) => {
|
||||
onViewChanged?.(view);
|
||||
},
|
||||
[onViewChanged],
|
||||
);
|
||||
|
||||
const handleOnUpdate = useCallback(
|
||||
(viewUpdate) => {
|
||||
if (viewUpdate.selectionSet && onSelectionChange) {
|
||||
|
|
@ -128,6 +131,7 @@ export default function CodeMirror({
|
|||
},
|
||||
[onSelectionChange],
|
||||
);
|
||||
|
||||
const extensions = useMemo(() => {
|
||||
let bindings = {
|
||||
vim,
|
||||
|
|
@ -138,6 +142,11 @@ export default function CodeMirror({
|
|||
}
|
||||
return staticExtensions;
|
||||
}, [keybindings]);
|
||||
|
||||
const setAutoCompletion = isAutoCompletionEnabled => isAutoCompletionEnabled ?
|
||||
javascriptLanguage.data.of({ autocomplete: strudelAutocomplete }) :
|
||||
autocompletion({ override: [] })
|
||||
|
||||
return (
|
||||
<div style={{ fontSize, fontFamily }} className="w-full">
|
||||
<_CodeMirror
|
||||
|
|
@ -146,7 +155,7 @@ export default function CodeMirror({
|
|||
onChange={handleOnChange}
|
||||
onCreateEditor={handleOnCreateEditor}
|
||||
onUpdate={handleOnUpdate}
|
||||
extensions={extensions}
|
||||
extensions={[ ...extensions, setAutoCompletion(isAutoCompletionEnabled) ]}
|
||||
basicSetup={{ lineNumbers: isLineNumbersDisplayed }}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue