santaclose / ImGuiColorTextEdit

Colorizing text editor for ImGui
MIT License
67 stars 18 forks source link

Show Matching Brackets Bug #12

Closed goossens closed 1 year ago

goossens commented 1 year ago

Commit https://github.com/santaclose/ImGuiColorTextEdit/commit/0226e184f1060d5cd88c00e63263d23cb81e2458 (show matching brackets) is a wonderful feature that I already had in my fork and it’s great to have it here. Unfortunately, there is a bug since it doesn’t handle empty lines correctly when it’s finding matching brackets.

Commit https://github.com/goossens/ImGuiColorTextEdit/commit/6ff7321972a8bc6cb7c313bd667a7515c2022cc6 in my fork fixes the problem and as a bonus, it makes the “show matching brackets” optional.

Let me know if you want a pull request.

santaclose commented 1 year ago

do you have a text sample to reproduce this issue? I remember I added code to handle this 🤔 maybe I missed some corner case.

goossens commented 1 year ago

Try:

if (true) {

} and put the cursor before the closing curly bracket. It will now create a negative value for currentCharIndex as it processes the empty line before it. The problem is line 1399:

currentCharIndex = mLines[currentLine].size() - 1;

Once you have a negative number, it will loop forever.

To keep things balanced, I also fixed the forward search.

santaclose commented 1 year ago

this should be working now, and should also be working when one of the brackets is not visible