tview icon indicating copy to clipboard operation
tview copied to clipboard

fix: fixed GetRegionText when colors are active

Open sruehl opened this issue 3 years ago • 2 comments

This PR fixes https://github.com/rivo/tview/issues/751

When skipping color tags the currentTag is getting incremented and directly after that a index access with that happens. This always crashes on the last tag.

Without this fix GetRegionText is unusable when color is active

sruehl avatar Aug 05 '22 13:08 sruehl

@rivo this is a pretty simple fix. Would be great if that could be merged as without colors can't be used in conjunction of GetRegionText

sruehl avatar Aug 05 '22 13:08 sruehl

I agree this is a bug so thank you for spotting it.

But your commit doesn't solve this issue or, said differently, it introduces another bug. Line 627 should never use the incremented currentTag value. If you simply add a bounds check, continue will not execute when it should, namely for the last colour tag which is not empty ([]).

It should look like this:

tag := currentTag
if pos == colorTagIndices[tag][1]-1 {
	currentTag++
}
if colorTagIndices[tag][1]-colorTagIndices[tag][0] > 2 {
	continue
}

If you modify your PR accordingly, I'll merge it.

rivo avatar Aug 11 '22 20:08 rivo

Oh sorry, somehow one of my github orgs spams so much notifications that your message didn't reach me. I will fix that ASAP.

I force-pushed your suggestions.

sruehl avatar Sep 05 '22 12:09 sruehl