From 6758d2a78710ea5ca1f775242e94564c2adb3908 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 2 Aug 2021 12:59:40 -0700 Subject: [PATCH] Document WordWrap bug --- util.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/util.go b/util.go index bc405e1..83254ea 100644 --- a/util.go +++ b/util.go @@ -528,7 +528,10 @@ func TaggedStringWidth(text string) int { // // Text is always split at newline characters ('\n'). // -// Text must not be escaped. +// BUG(tslocum) Text containing square brackets is not escaped properly. +// Use TextView.SetWrapWidth where possible. +// +// Issue: https://code.rocketnine.space/tslocum/cview/issues/27 func WordWrap(text string, width int) (lines []string) { colorTagIndices, _, _, _, escapeIndices, strippedText, _ := decomposeText([]byte(text), true, false) @@ -550,7 +553,7 @@ func WordWrap(text string, width int) (lines []string) { for index := escapePos; index >= 0; index-- { if index < len(escapeIndices) && startIndex > escapeIndices[index][0] && startIndex < escapeIndices[index][1]-1 { pos := escapeIndices[index][1] - 2 - startIndex - if pos < 0 || pos > len(substr) { + if pos < 0 || pos > len(substr) { // Workaround for issue #27 return substr } return substr[:pos] + substr[pos+1:] @@ -575,7 +578,7 @@ func WordWrap(text string, width int) (lines []string) { } // Is this a breakpoint? - if breakpointPos < len(breakpoints) && textPos+tagOffset == breakpoints[breakpointPos][0]+1 { + if breakpointPos < len(breakpoints) && textPos+tagOffset == breakpoints[breakpointPos][0] { // Yes, it is. Set up breakpoint infos depending on its type. lastBreakpoint = breakpoints[breakpointPos][0] + tagOffset lastContinuation = breakpoints[breakpointPos][1] + tagOffset