1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-05 00:59:19 +02:00

support wide characters in the editor

This commit is contained in:
Jesse Duffield
2021-02-09 09:47:57 +11:00
committed by github-actions[bot]
parent e7fff2529c
commit 56a573de86
13 changed files with 2093 additions and 57 deletions

View File

@ -343,17 +343,18 @@ func (v *View) writeRune(x, y int, ch rune) error {
}
olen := len(v.lines[y])
w := runewidth.RuneWidth(ch)
var s []cell
if x >= len(v.lines[y]) {
s = make([]cell, x-len(v.lines[y])+1)
s = make([]cell, x-len(v.lines[y])+w)
} else if !v.Overwrite {
s = make([]cell, 1)
s = make([]cell, w)
}
v.lines[y] = append(v.lines[y], s...)
if !v.Overwrite || (v.Overwrite && x >= olen-1) {
copy(v.lines[y][x+1:], v.lines[y][x:])
if !v.Overwrite || (v.Overwrite && x >= olen-w) {
copy(v.lines[y][x+w:], v.lines[y][x:])
}
v.lines[y][x] = cell{
fgColor: v.FgColor,
@ -361,6 +362,14 @@ func (v *View) writeRune(x, y int, ch rune) error {
chr: ch,
}
for i := 1; i < w; i++ {
v.lines[y][x+i] = cell{
fgColor: v.FgColor,
bgColor: v.BgColor,
chr: '\x00',
}
}
return nil
}
@ -384,7 +393,7 @@ func (v *View) deleteRune(x, y int) (int, error) {
w := runewidth.RuneWidth(v.lines[y][i].chr)
tw += w
if tw > x {
v.lines[y] = append(v.lines[y][:i], v.lines[y][i+1:]...)
v.lines[y] = append(v.lines[y][:i], v.lines[y][i+w:]...)
return w, nil
}