mirror of https://github.com/rivo/tview.git
Added support for zero-width joiners. Resolves #161
This commit is contained in:
parent
fed6446838
commit
29458dad3e
12
textview.go
12
textview.go
|
@ -883,8 +883,12 @@ func (t *TextView) Draw(screen tcell.Screen) {
|
||||||
comb = make([]rune, len(runeSequence)-1)
|
comb = make([]rune, len(runeSequence)-1)
|
||||||
copy(comb, runeSequence[1:])
|
copy(comb, runeSequence[1:])
|
||||||
}
|
}
|
||||||
for offset := 0; offset < runeSeqWidth; offset++ {
|
for offset := runeSeqWidth - 1; offset >= 0; offset-- {
|
||||||
|
if offset == 0 {
|
||||||
screen.SetContent(x+posX+offset, y+line-t.lineOffset, runeSequence[0], comb, style)
|
screen.SetContent(x+posX+offset, y+line-t.lineOffset, runeSequence[0], comb, style)
|
||||||
|
} else {
|
||||||
|
screen.SetContent(x+posX+offset, y+line-t.lineOffset, ' ', nil, style)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance.
|
// Advance.
|
||||||
|
@ -926,14 +930,18 @@ func (t *TextView) Draw(screen tcell.Screen) {
|
||||||
// Determine the width of this rune.
|
// Determine the width of this rune.
|
||||||
chWidth := runewidth.RuneWidth(ch)
|
chWidth := runewidth.RuneWidth(ch)
|
||||||
if chWidth == 0 {
|
if chWidth == 0 {
|
||||||
// If this is not a modifier, we treat it as a space character.
|
|
||||||
if len(runeSequence) == 0 {
|
if len(runeSequence) == 0 {
|
||||||
|
// If this is not a modifier, we treat it as a space character.
|
||||||
ch = ' '
|
ch = ' '
|
||||||
chWidth = 1
|
chWidth = 1
|
||||||
} else {
|
} else {
|
||||||
runeSequence = append(runeSequence, ch)
|
runeSequence = append(runeSequence, ch)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
} else if runeSequence[len(runeSequence)-1] == '\u200d' {
|
||||||
|
// Keep collecting if the previous character was a zero-width joiner.
|
||||||
|
runeSequence = append(runeSequence, ch)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip to the right.
|
// Skip to the right.
|
||||||
|
|
13
util.go
13
util.go
|
@ -321,7 +321,7 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
|
||||||
colorPos, escapePos int
|
colorPos, escapePos int
|
||||||
foregroundColor, backgroundColor, attributes string
|
foregroundColor, backgroundColor, attributes string
|
||||||
)
|
)
|
||||||
runeSequence := make([]rune, 0, 10)
|
runeSequence := make([]rune, 0, 20)
|
||||||
runeSeqWidth := 0
|
runeSeqWidth := 0
|
||||||
flush := func() {
|
flush := func() {
|
||||||
if len(runeSequence) == 0 {
|
if len(runeSequence) == 0 {
|
||||||
|
@ -339,9 +339,13 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
|
||||||
comb = make([]rune, len(runeSequence)-1)
|
comb = make([]rune, len(runeSequence)-1)
|
||||||
copy(comb, runeSequence[1:])
|
copy(comb, runeSequence[1:])
|
||||||
}
|
}
|
||||||
for offset := 0; offset < runeSeqWidth; offset++ {
|
for offset := runeSeqWidth - 1; offset >= 0; offset-- {
|
||||||
// To avoid undesired effects, we place the same character in all cells.
|
// To avoid undesired effects, we place the same character in all cells.
|
||||||
|
if offset == 0 {
|
||||||
screen.SetContent(finalX+offset, y, runeSequence[0], comb, finalStyle)
|
screen.SetContent(finalX+offset, y, runeSequence[0], comb, finalStyle)
|
||||||
|
} else {
|
||||||
|
screen.SetContent(finalX+offset, y, ' ', nil, finalStyle)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance and reset.
|
// Advance and reset.
|
||||||
|
@ -384,8 +388,9 @@ func printWithStyle(screen tcell.Screen, text string, x, y, maxWidth, align int,
|
||||||
ch = ' '
|
ch = ' '
|
||||||
chWidth = 1
|
chWidth = 1
|
||||||
}
|
}
|
||||||
} else {
|
} else if len(runeSequence) > 0 && runeSequence[len(runeSequence)-1] != '\u200d' {
|
||||||
// We have a character. Flush all previous runes.
|
// We have a character that doesn't follow a zero-width joiner. Flush all
|
||||||
|
// previous runes.
|
||||||
flush()
|
flush()
|
||||||
}
|
}
|
||||||
runeSequence = append(runeSequence, ch)
|
runeSequence = append(runeSequence, ch)
|
||||||
|
|
Loading…
Reference in New Issue