1
0
Fork 0
gilo/editor/row.go

40 lines
602 B
Go
Raw Normal View History

2021-03-30 16:05:33 -04:00
package editor
import "strings"
2021-03-30 16:05:33 -04:00
type row struct {
chars []rune
render []rune
2021-03-30 16:05:33 -04:00
}
func newRow(s string) *row {
2021-03-30 18:00:06 -04:00
var chars []rune
var render []rune
2021-03-30 18:00:06 -04:00
for _, ch := range s {
chars = append(chars, ch)
render = append(render, ch)
2021-03-30 18:00:06 -04:00
}
return &row {chars, render}
2021-03-30 16:05:33 -04:00
}
func (r *row) size() int {
2021-03-30 16:05:33 -04:00
return len(r.chars)
}
func (r *row) rSize() int {
return len(r.render)
}
func (r *row) update() {
r.render = r.render[:0]
replacement := strings.Repeat(" ", KiloTabStop)
str := strings.ReplaceAll(string(r.chars), "\t", replacement)
for _, ch := range str {
r.render = append(r.render, ch)
}
}
2021-03-30 16:05:33 -04:00