uiwjs / uiwjs/react-codemirror

Browser spell checking doesn't correct incorrect word

Open
#665 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2.3k
Forks
161
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the CodeMirror setup shown in the issue, especially the spellCheck prop and EditorView.contentAttributes spellcheck setting. Reproduce the right-click suggestion flow in the reported Next.js app and compare it with the working CodeSandbox case; done means selecting a browser spelling suggestion replaces the incorrect word.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, react, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.