fabiospampinato / vscode-highlight

Advanced text highlighter based on regexes. Useful for todos, annotations etc.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Entire line highlighted during input

chmac opened this issue · comments

Firstly, here's the config:

      "([\\s]*- \\[ \\] )": {
        "regexFlags": "g",
        "filterLanguageRegex": "markdown",
        "decorations": [{ "color": "black", "backgroundColor": "lightgreen" }]
      }

Then it's easiest to explain the issue with a screen capture:

Screen.Recording.2022-02-21.at.11.12.20.mov

The pattern should only match - [ ] but somehow during input, the match extends to the end of the line until a newline is entered. Just to clarify, this behaviour happens whether or not the current line is the last line of the file or not.

Edit: Also, to be clear, the word Two is not supposed to be highlighted in the screencapture.

I came to report the same issue. For clarity, here is a simpler configuration:

    "(a)": {
      "decorations": [{ "color": "black", "backgroundColor": "lightgreen" }]
    },

This should only match the character a, but anything typed after the a will be highlighted as well (until you enter a newline, or switch to a different tab and back, or reload the browser, etc.).

@chmac As a partial workaround, try this:

    "([\\s]*- \\[ \\] )(.*)": {
      "regexFlags": "g",
      "filterLanguageRegex": "markdown",
      "decorations": [
        { "color": "black", "backgroundColor": "lightgreen" },
        {}
      ]
    }

This sets up a second capturing group, with no decoration, to get everything after - [ ] . This will fail to highlight any further occurrences of - [ ] on the same line, but presumably that's not a big issue.

@TheophileMot Oh nice, that's a neat trick to add a second group. I hadn't considered finding workarounds as I don't find it so distracting, but this is a simple and neat trick, I'll do it. Thanks for sharing.

@chmac Glad to help. Incidentally, I see now that this issue is the same as #31 (there's an extended discussion of the problem there).

@TheophileMot Nice catch, I totally missed #31. Closing this now in favour of #31. Thanks.