davraamides / todotxt-mode

MIT License
59 stars 12 forks source link

Whitespace at beginning of line throws of syntax highlighting #11

Closed mhkeller closed 4 years ago

mhkeller commented 4 years ago

If I'm using this in a markdown file, I might have this in an indented list where the line begins with whitespace. Some things get highlighted but there's an offset. See the comparison between lines 2 and 3 below:

Screen Shot 2020-01-08 at 5 34 02 PM

davraamides commented 4 years ago

I’m not sure if leading white space is valid in the todotxt format. But let me look at how difficult this would be to support. If it’s a simple fix and doesn’t break anything, I will make the change.

mhkeller commented 4 years ago

I did some preliminary looking into this and it seems that removing line.firstNonWhitespaceCharacterIndex from here improves some of it.

With those lines changed to the below, the priority label is still not working but the other highlights are now at the correct index. Looking at the code, the priority logic is a little more complicated. This change doesn't seem to break other styling but I haven't tried the more advanced task features.

let begPos = new vscode.Position(line.range.start.line, result.index);
let endPos = new vscode.Position(line.range.start.line, result.index + result[0].length);

Screen Shot 2020-01-13 at 1 19 15 PM

davraamides commented 4 years ago

Hi Michael,

I looked at this too and came to the same conclusion. The issue with the priority is due to the beginning of line anchor in the regex (^) but when I tried adding in optional leading white space to the pattern, (^\s*) it broke the sorting.

Maybe this is such an edge case that it doesn’t matter. I can push changes to get the formatting working and revisit the sorting logic later.

-David

On Jan 13, 2020, at 1:19 PM, Michael Keller notifications@github.com wrote:

 I did some preliminary looking into this and it seems that removing linefirstNonWhitespaceCharacterIndex from here improves some of it.

With those lines changed to the below, the priority label is still not working but the other highlights are now at the correct index. Looking at the code, the priority logic is a little more complicated. This change doesn't seem to break other styling but I haven't tried the more advanced task features.

let begPos = new vscode.Position(line.range.start.line, result.index); let endPos = new vscode.Position(line.range.start.line, result.index + result[0].length);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

mhkeller commented 4 years ago

Sounds good! Thanks for looking into it. Whatever you think minimizes any negative side effects.

davraamides commented 4 years ago

Fixed with 1.4.12 release.

mhkeller commented 4 years ago

Thanks for your time and work on this! It's much appreciated!