You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
chenbinli-dev
changed the title
Why does the autocomplete integration not work in reaction-codemirror?
Why does the autocomplete integration not work in react-codemirror?
Sep 23, 2023
importReactfrom"react";importCodeMirrorfrom"@uiw/react-codemirror";import{autocompletion}from"@codemirror/autocomplete";// Our list of completions (can be static, since the editor/// will do filtering based on context).constcompletions=[{label: "panic",type: "keyword"},{label: "park",type: "constant",info: "Test completion"},{label: "password",type: "variable"}];functionmyCompletions(context){letbefore=context.matchBefore(/\w+/);// If completion wasn't explicitly started and there// is no word before the cursor, don't open completions.if(!context.explicit&&!before)returnnull;return{from: before ? before.from : context.pos,options: completions,validFor: /^\w*$/};}functionApp(){const[value,setValue]=React.useState("// Type a 'p'\n");constonChange=React.useCallback((val,viewUpdate)=>{console.log("val:",val);setValue(val);},[]);return(<CodeMirrorvalue={value}height="200px"extensions={[autocompletion({override: [myCompletions]})]}onChange={onChange}/>);}exportdefaultApp;
https://codesandbox.io/p/sandbox/react-codemirror-tzhnch.
The text was updated successfully, but these errors were encountered: