From 3d5f294a6fcacb5448d76a1f4116c6827a8f0869 Mon Sep 17 00:00:00 2001 From: rivo <480930+rivo@users.noreply.github.com> Date: Thu, 3 May 2018 18:57:25 +0200 Subject: [PATCH] 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. --- cell.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cell.go b/cell.go index b54abcb..496f10f 100644 --- a/cell.go +++ b/cell.go @@ -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 } }