40 lines
602 B
Go
40 lines
602 B
Go
package editor
|
|
|
|
import "strings"
|
|
|
|
type row struct {
|
|
chars []rune
|
|
render []rune
|
|
}
|
|
|
|
func newRow(s string) *row {
|
|
var chars []rune
|
|
var render []rune
|
|
|
|
for _, ch := range s {
|
|
chars = append(chars, ch)
|
|
render = append(render, ch)
|
|
}
|
|
|
|
return &row {chars, render}
|
|
}
|
|
|
|
func (r *row) size() int {
|
|
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)
|
|
}
|
|
}
|
|
|