Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlightSelectionMatches not working #316

Open
Shivansh-5 opened this issue Nov 11, 2024 · 0 comments
Open

highlightSelectionMatches not working #316

Shivansh-5 opened this issue Nov 11, 2024 · 0 comments

Comments

@Shivansh-5
Copy link

Shivansh-5 commented Nov 11, 2024

Hi,
It is mentioned in the docs that after importing this file 'codemirror/addon/search/match-highlighter', this 'highlightSelectionMatches' option can be added which can be enabled to highlight all instances of the selected word,
but this does not work.

This is the code, I don't know if I am doing something wrong:

import React from 'react';

import { Controlled as CodeMirror } from 'react-codemirror2';
import 'codemirror/theme/material.css';
import 'codemirror/lib/codemirror.css';
import "codemirror/mode/jsx/jsx";
import 'codemirror/addon/hint/show-hint';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/lint/lint';
import 'codemirror/addon/hint/javascript-hint';
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/addon/edit/closebrackets';
import 'codemirror/addon/edit/closetag';
import 'codemirror/addon/fold/foldcode';
import 'codemirror/addon/fold/foldgutter';
import 'codemirror/addon/fold/brace-fold';
import "codemirror/addon/selection/active-line";
import 'codemirror/addon/fold/comment-fold';
import 'codemirror/addon/fold/foldgutter.css';
import './App.css';
import 'codemirror/addon/search/match-highlighter';

function CodeEditor() {
  const [code, setCode] = React.useState('// my code goes here');
  return (
    <CodeMirror
      className='CodeMirror'
      value={code}
      options={{
        mode: 'jsx',
        theme: 'material',
        lineWrapping: true,
        smartIndent: true,
        lineNumbers: true,
        autofocus: true,
        foldGutter: true,
        gutters: ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
        autoCloseTags: true,
        highlightSelectionMatches: true,
        styleActiveLine: true,
      }}
      onBeforeChange={(editor, data, value) => {
        editor.showHint({
          completeSingle: false,
          closeOnPick: false,
        });
        setCode(value);
      }}
    />
  );
}

export default CodeEditor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant