The logic here needs some cleanup:

```
        if (endChar < startChar) {
            query = this.editor.document.getRange({
                line: cursor.line,
                ch: startChar
            }, cursor);
        }

        if (endChar < startChar) {
            return query;
        }
            
        return null;
```

1. No need to check for `(endChar < startChar)` twice.

2. The `(endChar < startChar)` condition relies on the fact that "not found" is represented by -1 so it seems a bit cryptic. Please reverse the logic and add a comment.

3. There was a check that startChar was found that got dropped. Maybe that was (cryptically) handled by the `endChar === startChar` case, but I think you need it here:

```
        // If no startChar, or endChar is found after startChar, then not in an entity
        if (startChar === -1 || endChar > startChar) {
            return null;
        }

        query = this.editor.document.getRange({
            line: cursor.line,
            ch: startChar
        }, cursor);

        return query;
```