kotcrab/vis-ui

Cursor offset for highlighted blocks in HighlightTextArea wrong

Opened this issue · 3 comments

If I have multible Highlighted areas in a HighlightTextArea on the same line, the cursor position gets offset to the left a bit more per block.

Code Example for reproduction: https://pastebin.com/vnYv9qg2

Used Java version: JavaSE11
used libGDX version: 1.9.9 with lwjgl3 backend
Used visUI version: 1.4.2

In the attached screenshot you can see that the cursor is offset way off to the right even tho the cursor position is at the end of the line which is right behind the word "false" (there are no spaces after that).
20190504160646_1

Looks like this is an issue with kerning. X offset of highlight is calculated only on the highlighted text itself while cursor is using glyph positions calculated on the entire text. Unfortunately I'm not seeing an easy fix for this.

By the way, in your regex you can use ^ to match start of the line.

Is there any way to work around this then? Maybe use a diffrent font or something?

Thanks for the tip with ^, I am already using that somewhere else and just didnt change it in this example.

You can try using any monospaced font. They don't use kerning and it should work better in general for code-type stuff. Or you can drop the rule for |, highlighting entire words seems to work okay.