scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.66k stars 193 forks source link

defineMode does not work #140

Closed GongJS closed 5 years ago

GongJS commented 5 years ago

this is my code:

this.state = {
   logs: 'this is a new log',
   keyword: 'log'
}
<CodeMirror
         value={this.state.logs}
         editorDidMount={editor => { this.instance = editor }}
             defineMode={{
                 name: 'highlightSearch', 
                 fn: () => {
                    return {
                      // startState: () => ({}),
                      token: (stream) => {
                        const keyword = this.state.keyword;
                        if (keyword !== '' && stream.match(keyword)) {
                           return "highlightSearch";
                        }
                       while (stream.next() != null && !stream.match(keyword, false)) {}
                       return null;
                }  
            }
        }
    }}
/>

.cm-highlightSearch {
  background: red;
  color: #fff;
}

i want to highlight the keyword of 'log', but i find it does not work. it seems that the defineMode does not work...

my version is 6.0.0

scniro commented 5 years ago

@GongJS The demo has a working defineMode example (fn source). I'd suggest taking a look at your function, as it should be passing it as expected through the wrapper.

GongJS commented 5 years ago

ok,thank you.