uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.69k stars 134 forks source link

Browser spell checking doesn't correct incorrect word #665

Open atilara opened 5 months ago

atilara commented 5 months ago

Hey,

The words are not corrected when I right click on a word and click on a suggestion:

https://github.com/uiwjs/react-codemirror/assets/45675035/f62f3fd6-b96f-462e-8f57-70381be6e984

That's the setup I did:

'use client';
import { useCallback, useState } from 'react';
import CodeMirror from '@uiw/react-codemirror';

import { EditorState } from '@codemirror/state';
import { EditorView } from '@uiw/react-codemirror';

import Box from '@mui/material/Box';

export default function CodeMirrorEditor() {
  const portuguesePhrases = {
    // @codemirror/view
    'Control character': 'Controlar cursor',
    // @codemirror/commands
    'Selection deleted': 'Seleção deletada',
    // @codemirror/language
    'Folded lines': 'Linhas dobradas',
    'Unfolded lines': 'Linhas desdobradas',
    to: 'para',
    'folded code': 'código dobrado',
    unfold: 'desdobrar',
    'Fold line': 'Dobrar linha',
    'Unfold line': 'Desdobrar linha',
    // @codemirror/search
    'Go to line': 'Ir para linha',
    go: 'OK',
    Find: 'Encontrar',
    Replace: 'Substituir',
    next: 'próximo',
    previous: 'anterior',
    all: 'todos',
    'match case': 'Diferenciar Maiúsculas de Minúsculas',
    'by word': 'Coincidir Palavra Inteira',
    replace: 'substituir',
    'replace all': 'substituir todos',
    close: 'fechar',
    'current match': 'Correspondência atual',
    'replaced $ matches': '$ correspondências substituídas',
    'replaced match on line $': 'Correspondência substituída na linha $',
    'on line': 'na linha',
    // @codemirror/autocomplete
    Completions: 'Sugestões',
    // @codemirror/lint
    Diagnostics: 'Diagnóstico',
    'No diagnostics': 'Não há diagnóstico',
  };

  const [value, setValue] = useState('Hello world!');

  const onChange = useCallback((val: string) => {
    setValue(val);
  }, []);

  return (
    <Box>
      <CodeMirror
        value={value}
        onChange={onChange}
        extensions={[
          EditorState.phrases.of(portuguesePhrases),
          EditorView.lineWrapping,
          EditorView.contentAttributes.of({ spellcheck: 'true' }),
        ]}
        spellCheck={true}
        height="100vh"
      />
    </Box>
  );
}

Any idea on how to fix that?

I'm using Next.js using app router and version ^4.22.2 of the @uiw/react-codemirror. Couldn't replicate on a code sandbox because it works properly there.

atilara commented 4 months ago

Replicated the problem in a codesanbox:

https://github.com/uiwjs/react-codemirror/assets/45675035/c10c09be-7591-4296-8d57-330e7928d088

Link: https://codesandbox.io/p/sandbox/codemirror-spellcheck-gxy26p

Apparently, the problem only happens in Chrome and Chrome based browsers like Brave and Edge, it works normally on Firefox. My chrome version is 126.0.6478.126.

atilara commented 4 months ago

Hey! Sorry to bother again :sweat_smile:

Any news about this?

jaywcjlove commented 4 months ago

@atilara I tried to help you solve the issue. I tested it and found that the problem might only exist in Next.js.

https://uiwjs.github.io/react-codemirror/#/examples/674

atilara commented 4 months ago

@jaywcjlove Thanks for taking your time to try to find a solution and answer this issue.

Is it supposed to work on the link you provided? It doesn't work here on chrome, only on firefox and other browsers that are not chrome based.

The example you sent uses React or Next?

It doesn't work on the CodeSandbox I sent and it runs on React there

jaywcjlove commented 4 months ago

https://github.com/user-attachments/assets/4eadd22a-f17a-4d59-98a8-c5bf07eceaf4

@atilara There are no issues in development mode, but the error reoccurs after deployment. I don't know why.

https://github.com/user-attachments/assets/b3fc9604-9dc2-41fb-8b64-6a0164822b94

atilara commented 4 months ago

@jaywcjlove That's weird. It doesn't work anywhere here, the problem is present on development and deployment.

Do you think this could be a problem from codemirror itself?

jaywcjlove commented 4 months ago

@atilara I believe it is likely a problem similar to #216, but it is still unclear what the cause is.

atilara commented 4 months ago

@jaywcjlove any way we could investigate this? Do you think the spellcheck extension is not being recognized?

jaywcjlove commented 3 months ago

@atilara I've investigated the error, but I couldn't find the cause of the issue.