Use DecodeCharacter over DecodeRune

This commit is contained in:
Zachary Yedidia
2020-05-20 16:43:12 -04:00
parent 65be5efd83
commit bdff221870
9 changed files with 106 additions and 33 deletions

View File

@@ -474,7 +474,7 @@ func (b *Buffer) RuneAt(loc Loc) rune {
if len(line) > 0 {
i := 0
for len(line) > 0 {
r, size := utf8.DecodeRune(line)
r, _, size := util.DecodeCharacter(line)
line = line[size:]
i++

View File

@@ -436,7 +436,7 @@ func (c *Cursor) RuneUnder(x int) rune {
}
i := 0
for len(line) > 0 {
r, size := utf8.DecodeRune(line)
r, _, size := util.DecodeCharacter(line)
line = line[size:]
if i == x {

View File

@@ -8,6 +8,7 @@ import (
"unicode/utf8"
"github.com/zyedidia/micro/v2/pkg/highlight"
"github.com/zyedidia/micro/v2/internal/util"
)
// Finds the byte index of the nth rune in a byte slice
@@ -19,7 +20,7 @@ func runeToByteIndex(n int, txt []byte) int {
count := 0
i := 0
for len(txt) > 0 {
_, size := utf8.DecodeRune(txt)
_, _, size := util.DecodeCharacter(txt)
txt = txt[size:]
count += size