From 0e90972fe8e0e93d67091bab3abdbeb8bdc066e1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 21 Mar 2018 19:46:27 +0200 Subject: Handle some corner cases in MessageView --- ui/widget/message-view.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ui/widget') diff --git a/ui/widget/message-view.go b/ui/widget/message-view.go index 78d37c1..941b987 100644 --- a/ui/widget/message-view.go +++ b/ui/widget/message-view.go @@ -22,6 +22,7 @@ import ( "github.com/gdamore/tcell" "github.com/mattn/go-runewidth" + "maunium.net/go/gomuks/ui/debug" "maunium.net/go/gomuks/ui/types" "maunium.net/go/tview" ) @@ -276,11 +277,15 @@ func (view *MessageView) Draw(screen tcell.Screen) { } view.writeLine(screen, message, x+messageOffsetX, y, tcell.ColorGreen) } + if len(view.textBuffer) != len(view.metaBuffer) { + debug.ExtPrintf("Unexpected text/meta buffer length mismatch: %d != %d.", len(view.textBuffer), len(view.metaBuffer)) + return + } for line := 0; line < height; line++ { index := indexOffset + line if index < 0 { continue - } else if index > len(view.textBuffer) { + } else if index >= len(view.textBuffer) { break } text, meta := view.textBuffer[index], view.metaBuffer[index] -- cgit v1.2.3