简体   繁体   中英

React Ace Editor highlighting keywords in the middle of other words

I am using the react ace editor. I have created a custom highlight rule as is documented elsewhere. The code is here:

export class CustomHighlightRules extends window.ace.acequire("ace/mode/text_highlight_rules").TextHighlightRules {
    constructor() {
      super();
      this.$rules = {
        start: [
          {
            token: "keyword",
            regex: "def"
          }
        ]
      };
    }
  }

The problem is that when I type something like def somedeftext into the editor, the word "def" in the very middle of "somedeftext" is highlighted incorrectly. What causes this behavior?

在单词中间突出显示

I found that changing the regex as follows works:

regex: "\\bdef\\b"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM