react-ace icon indicating copy to clipboard operation
react-ace copied to clipboard

setHighlightSelectedWord not working

Open AlonBe opened this issue 9 years ago • 3 comments

Hi there,

I just created a simple application with react-ace component. I've noticed that when I'm writing the same word twice and select an occurrence - the other occurrence is not being highlighted although it should be. I tried to use setHighlightSelectedWord(true) but the result is still the same.

Did it happen to anyone else?

AlonBe avatar Feb 14 '17 13:02 AlonBe

Sorry, forgot to add the code:

import React from 'react';

import AceEditor from 'react-ace';
import brace from 'brace';

import 'brace/mode/sql';
import 'brace/theme/monokai'; // So we could use it as the "theme" prop

class App extends React.Component {

    render() {
        return <AceEditor
            ref="aceEditor"
            mode="sql"
            theme="monokai"
            fontSize="1em"
        />;
    }

    componentDidMount(){
        this.refs.aceEditor.editor.setHighlightSelectedWord(true);
    }
}

export default App;

AlonBe avatar Feb 14 '17 13:02 AlonBe

Instead of using a componentDidMount, you can pass the editor options when rendering the editor initially:

import React from 'react';

import AceEditor from 'react-ace';
import brace from 'brace';

import 'brace/mode/sql';
import 'brace/theme/monokai'; // So we could use it as the "theme" prop

class App extends React.Component {

    render() {
        return <AceEditor
            ref="aceEditor"
            mode="sql"
            theme="monokai"
            fontSize="1em"
            setOptions={{
                  highlightSelectedWord: true
            }}
        />;
    }
}

export default App;

Worked for me, let me know if it works for you

drewen avatar May 13 '17 12:05 drewen

closing thanks @drewen !

securingsincity avatar May 25 '17 02:05 securingsincity