From 380278f41c18dc53e44dddba0e8e816fbad81d0c Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Mon, 29 Oct 2018 11:12:40 +0100 Subject: [PATCH] Bugfix in TextView. --- textview.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/textview.go b/textview.go index 7168990..00ac88c 100644 --- a/textview.go +++ b/textview.go @@ -872,18 +872,21 @@ func (t *TextView) Draw(screen tcell.Screen) { // Print the line. var colorPos, regionPos, escapePos, tagOffset, skipped int iterateString(strippedText, func(main rune, comb []rune, textPos, textWidth, screenPos, screenWidth int) bool { - // Get the color. - if colorPos < len(colorTags) && textPos+tagOffset >= colorTagIndices[colorPos][0] && textPos+tagOffset < colorTagIndices[colorPos][1] { - foregroundColor, backgroundColor, attributes = styleFromTag(foregroundColor, backgroundColor, attributes, colorTags[colorPos]) - tagOffset += colorTagIndices[colorPos][1] - colorTagIndices[colorPos][0] - colorPos++ - } - - // Get the region. - if regionPos < len(regionIndices) && textPos+tagOffset >= regionIndices[regionPos][0] && textPos+tagOffset < regionIndices[regionPos][1] { - regionID = regions[regionPos][1] - tagOffset += regionIndices[regionPos][1] - regionIndices[regionPos][0] - regionPos++ + // Process tags. + for { + if colorPos < len(colorTags) && textPos+tagOffset >= colorTagIndices[colorPos][0] && textPos+tagOffset < colorTagIndices[colorPos][1] { + // Get the color. + foregroundColor, backgroundColor, attributes = styleFromTag(foregroundColor, backgroundColor, attributes, colorTags[colorPos]) + tagOffset += colorTagIndices[colorPos][1] - colorTagIndices[colorPos][0] + colorPos++ + } else if regionPos < len(regionIndices) && textPos+tagOffset >= regionIndices[regionPos][0] && textPos+tagOffset < regionIndices[regionPos][1] { + // Get the region. + regionID = regions[regionPos][1] + tagOffset += regionIndices[regionPos][1] - regionIndices[regionPos][0] + regionPos++ + } else { + break + } } // Skip the second-to-last character of an escape tag. @@ -926,7 +929,7 @@ func (t *TextView) Draw(screen tcell.Screen) { } // Stop at the right border. - if posX+screenWidth >= width { + if posX+screenWidth > width { return true }