mirror of
https://github.com/gdamore/tcell.git
synced 2025-04-26 13:48:53 +08:00
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:
parent
5ddf16a669
commit
3d5f294a6f
8
cell.go
8
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 {
|
if x >= 0 && y >= 0 && x < cb.w && y < cb.h {
|
||||||
c := &cb.cells[(y*cb.w)+x]
|
c := &cb.cells[(y*cb.w)+x]
|
||||||
|
|
||||||
|
c.currComb = append([]rune{}, combc...)
|
||||||
i := 0
|
i := 0
|
||||||
for i < len(combc) {
|
for i < len(c.currComb) {
|
||||||
r := combc[i]
|
r := c.currComb[i]
|
||||||
if runewidth.RuneWidth(r) != 0 {
|
if runewidth.RuneWidth(r) != 0 {
|
||||||
// not a combining character, yank it
|
// 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
|
continue
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
@ -63,7 +64,6 @@ func (cb *CellBuffer) SetContent(x int, y int,
|
|||||||
c.width = runewidth.RuneWidth(mainc)
|
c.width = runewidth.RuneWidth(mainc)
|
||||||
}
|
}
|
||||||
c.currMain = mainc
|
c.currMain = mainc
|
||||||
c.currComb = combc
|
|
||||||
c.currStyle = style
|
c.currStyle = style
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user