Handle some corner cases in MessageView

This commit is contained in:
Tulir Asokan 2018-03-21 19:46:27 +02:00
parent 35b6c7bd27
commit 0e90972fe8

View File

@ -22,6 +22,7 @@ import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"maunium.net/go/gomuks/ui/debug"
"maunium.net/go/gomuks/ui/types" "maunium.net/go/gomuks/ui/types"
"maunium.net/go/tview" "maunium.net/go/tview"
) )
@ -276,11 +277,15 @@ func (view *MessageView) Draw(screen tcell.Screen) {
} }
view.writeLine(screen, message, x+messageOffsetX, y, tcell.ColorGreen) 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++ { for line := 0; line < height; line++ {
index := indexOffset + line index := indexOffset + line
if index < 0 { if index < 0 {
continue continue
} else if index > len(view.textBuffer) { } else if index >= len(view.textBuffer) {
break break
} }
text, meta := view.textBuffer[index], view.metaBuffer[index] text, meta := view.textBuffer[index], view.metaBuffer[index]