SetContent() now makes a copy of the combining characters slice. (#216)

* SetContent() now makes a copy of the combining characters slice. Avoids unexpected side effects when original slice is reused/modified. Fixes #215

* Appending combining characters to an empty rune slice instead of making a copy.
This commit is contained in:
rivo 2018-05-03 18:57:25 +02:00 committed by Garrett D'Amore
parent 5ddf16a669
commit 3d5f294a6f
1 changed files with 4 additions and 4 deletions

View File

@ -48,12 +48,13 @@ func (cb *CellBuffer) SetContent(x int, y int,
if x >= 0 && y >= 0 && x < cb.w && y < cb.h {
c := &cb.cells[(y*cb.w)+x]
c.currComb = append([]rune{}, combc...)
i := 0
for i < len(combc) {
r := combc[i]
for i < len(c.currComb) {
r := c.currComb[i]
if runewidth.RuneWidth(r) != 0 {
// not a combining character, yank it
combc = append(combc[:i-1], combc[i+1:]...)
c.currComb = append(c.currComb[:i-1], c.currComb[i+1:]...)
continue
}
i++
@ -63,7 +64,6 @@ func (cb *CellBuffer) SetContent(x int, y int,
c.width = runewidth.RuneWidth(mainc)
}
c.currMain = mainc
c.currComb = combc
c.currStyle = style
}
}