Cut TextEdit Draw time in half
This commit is contained in:
parent
b9a8b0040a
commit
27b2f564eb
@ -365,10 +365,9 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
lineHighlightData := t.Highlighter.GetLineMatches(line)
|
lineHighlightData := t.Highlighter.GetLineMatches(line)
|
||||||
var lineHighlightDataIdx int
|
var lineHighlightDataIdx int
|
||||||
|
|
||||||
var byteIdx int // Byte index of lineStr
|
var byteIdx int // Byte index of lineStr
|
||||||
// X offset we draw the next rune at (some runes can be 2 cols wide)
|
var runeIdx int // Index into lineStr (as runes) we draw the next character at
|
||||||
col := t.x + columnWidth
|
col := t.x + columnWidth // X offset we draw the next rune at (some runes can be 2 cols wide)
|
||||||
var runeIdx int // Index into lineStr (as runes) we draw the next character at
|
|
||||||
|
|
||||||
for runeIdx < t.scrollx && byteIdx < len(lineBytes) {
|
for runeIdx < t.scrollx && byteIdx < len(lineBytes) {
|
||||||
_, size := utf8.DecodeRune(lineBytes[byteIdx:]) // Respect UTF-8
|
_, size := utf8.DecodeRune(lineBytes[byteIdx:]) // Respect UTF-8
|
||||||
@ -378,13 +377,10 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
|
|
||||||
tabOffsetAtRuneIdx := func(idx int) int {
|
tabOffsetAtRuneIdx := func(idx int) int {
|
||||||
var count int
|
var count int
|
||||||
var i int
|
for _, r := range string(origLineBytes) {
|
||||||
for i < len(origLineBytes) {
|
|
||||||
r, size := utf8.DecodeRune(origLineBytes[i:])
|
|
||||||
if r == '\t' {
|
if r == '\t' {
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
i += size
|
|
||||||
}
|
}
|
||||||
return count * (t.TabSize - 1)
|
return count * (t.TabSize - 1)
|
||||||
}
|
}
|
||||||
@ -393,9 +389,11 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
// not affected by the hard tabs becoming 4 or 8 spaces.
|
// not affected by the hard tabs becoming 4 or 8 spaces.
|
||||||
origRuneIdx := func(idx int) int { // returns the idx that is not mutated by hard tabs
|
origRuneIdx := func(idx int) int { // returns the idx that is not mutated by hard tabs
|
||||||
var ridx int // new rune idx
|
var ridx int // new rune idx
|
||||||
var i int // byte index
|
for _, r := range string(origLineBytes) {
|
||||||
for idx > 0 {
|
if idx <= 0 {
|
||||||
r, size := utf8.DecodeRune(origLineBytes[i:])
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if r == '\t' {
|
if r == '\t' {
|
||||||
idx -= t.TabSize
|
idx -= t.TabSize
|
||||||
} else {
|
} else {
|
||||||
@ -404,7 +402,6 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
if idx >= 0 { // causes ridx = 0, when idx = 3
|
if idx >= 0 { // causes ridx = 0, when idx = 3
|
||||||
ridx++
|
ridx++
|
||||||
}
|
}
|
||||||
i += size
|
|
||||||
}
|
}
|
||||||
return ridx
|
return ridx
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user