diff --git a/textview.go b/textview.go index 1a445bb..fa7c662 100644 --- a/textview.go +++ b/textview.go @@ -1019,14 +1019,22 @@ func (t *TextView) Draw(screen tcell.Screen) { backgroundColor := index.BackgroundColor attributes := index.Attributes regionID := index.Region - if t.regions && regionID != "" && (len(t.regionInfos) == 0 || t.regionInfos[len(t.regionInfos)-1].ID != regionID) { - t.regionInfos = append(t.regionInfos, &textViewRegion{ - ID: regionID, - FromX: x, - FromY: y + line - t.lineOffset, - ToX: -1, - ToY: -1, - }) + if t.regions { + if len(t.regionInfos) > 0 && t.regionInfos[len(t.regionInfos)-1].ID != regionID { + // End last region. + t.regionInfos[len(t.regionInfos)-1].ToX = x + t.regionInfos[len(t.regionInfos)-1].ToY = y + line - t.lineOffset + } + if regionID != "" && (len(t.regionInfos) == 0 || t.regionInfos[len(t.regionInfos)-1].ID != regionID) { + // Start a new region. + t.regionInfos = append(t.regionInfos, &textViewRegion{ + ID: regionID, + FromX: x, + FromY: y + line - t.lineOffset, + ToX: -1, + ToY: -1, + }) + } } // Process tags.