@@ -12,6 +12,8 @@ import (
1212 "fyne.io/fyne/v2/internal/painter"
1313 "fyne.io/fyne/v2/internal/widget"
1414 "fyne.io/fyne/v2/theme"
15+
16+ "github.com/mattn/go-runewidth"
1517)
1618
1719const (
@@ -209,6 +211,8 @@ func (t *TextGrid) Text() string {
209211 runes = append (runes , cell .Rune )
210212 if cell .Rune == '\t' {
211213 next = nextTab (col , t .tabWidth ())
214+ } else {
215+ next = col + runewidth .StringWidth (string (cell .Rune ))
212216 }
213217 }
214218 if i < len (t .Rows )- 1 {
@@ -249,6 +253,8 @@ func (t *TextGrid) RowText(row int) string {
249253 runes = append (runes , cell .Rune )
250254 if cell .Rune == '\t' {
251255 next = nextTab (col , t .tabWidth ())
256+ } else {
257+ next = col + runewidth .StringWidth (string (cell .Rune ))
252258 }
253259 }
254260 return string (runes )
@@ -399,14 +405,18 @@ func (t *TextGrid) parseRows(text string) []TextGridRow {
399405 rows := make ([]TextGridRow , len (lines ))
400406 for i , line := range lines {
401407 cells := make ([]TextGridCell , 0 , len (line ))
408+ next := 0
409+ col := 0
402410 for _ , r := range line {
403411 cells = append (cells , TextGridCell {Rune : r })
404412 if r == '\t' {
405- col := len (cells )
406- next := nextTab (col - 1 , t .tabWidth ())
407- for i := col ; i < next ; i ++ {
408- cells = append (cells , TextGridCell {Rune : ' ' })
409- }
413+ col = len (cells )
414+ next = nextTab (col - 1 , t .tabWidth ())
415+ } else {
416+ next = col - 1 + runewidth .StringWidth (string (r ))
417+ }
418+ for i := col ; i < next ; i ++ {
419+ cells = append (cells , TextGridCell {Rune : ' ' })
410420 }
411421 }
412422 rows [i ] = TextGridRow {Cells : cells }
0 commit comments