Skip to content

Commit

Permalink
fix: fix EditorView.update errors (#280).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 27, 2022
1 parent 971aca7 commit acffc46
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/useCodeMirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ export function useCodeMirror(props: UseCodeMirror) {
getExtensions.unshift(keymap.of([indentWithTab]));
}
if (defaultBasicSetup) {
if (Array.isArray(basicSetup)) {
/**
* 🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧
* This is not a solution.
* https://github.com/uiwjs/react-codemirror/issues/280
*/
basicSetup.map((item) => {
if (item.value && Array.isArray(item.value)) {
item.value = item.value
.map((keymap: any) => {
if ('Mod-f' === keymap.key) {
return undefined;
}
return keymap;
})
.filter(Boolean);
}
return item;
});
}
getExtensions.unshift(basicSetup);
}

Expand Down Expand Up @@ -102,6 +122,11 @@ export function useCodeMirror(props: UseCodeMirror) {
setView(viewCurrent);
}
}
return () => {
if (view) {
setView(undefined);
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [container, state]);

Expand Down
1 change: 0 additions & 1 deletion website/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ let count = 0;

export default function App() {
const dark = document.documentElement.getAttribute('data-color-mode');
console.log('>>', document.documentElement.getAttribute('data-color-mode'));
const [mode, setMode] = useState('javascript');
const [placeholder, setPlaceholder] = useState('Please enter the code.');
const [autofocus, setAutofocus] = useState(false);
Expand Down

0 comments on commit acffc46

Please sign in to comment.