Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ func (b *SharedBuffer) calcHash(out *[md5.Size]byte) {
h := md5.New()

if len(b.lines) > 0 {
h.Write(b.lines[0].data)
h.Write(b.lines[0].data())

for _, l := range b.lines[1:] {
if b.Endings == FFDos {
h.Write([]byte{'\r', '\n'})
} else {
h.Write([]byte{'\n'})
}
h.Write(l.data)
h.Write(l.data())
}
}

Expand Down Expand Up @@ -866,7 +866,7 @@ func (b *Buffer) UpdateRules() {
if header.MatchFileName(b.Path) {
matchedFileName = true
}
if len(fnameMatches) == 0 && header.MatchFileHeader(b.lines[0].data) {
if len(fnameMatches) == 0 && header.MatchFileHeader(b.lines[0].data()) {
matchedFileHeader = true
}
} else if header.FileType == ft {
Expand Down Expand Up @@ -920,7 +920,7 @@ func (b *Buffer) UpdateRules() {
if header.MatchFileName(b.Path) {
fnameMatches = append(fnameMatches, syntaxFileInfo{header, f.Name(), nil})
}
if len(fnameMatches) == 0 && header.MatchFileHeader(b.lines[0].data) {
if len(fnameMatches) == 0 && header.MatchFileHeader(b.lines[0].data()) {
headerMatches = append(headerMatches, syntaxFileInfo{header, f.Name(), nil})
}
} else if header.FileType == ft {
Expand Down Expand Up @@ -953,7 +953,7 @@ func (b *Buffer) UpdateRules() {
for _, m := range matches {
if m.header.HasFileSignature() {
for i := 0; i < limit; i++ {
if m.header.MatchFileSignature(b.lines[i].data) {
if m.header.MatchFileSignature(b.lines[i].data()) {
syntaxFile = m.fileName
if m.syntaxDef != nil {
b.SyntaxDef = m.syntaxDef
Expand Down Expand Up @@ -1130,11 +1130,11 @@ func (b *Buffer) MoveLinesUp(start int, end int) {
if start < 1 || start >= end || end > len(b.lines) {
return
}
l := string(b.LineBytes(start - 1))
l := b.LineString(start - 1)
if end == len(b.lines) {
b.insert(
Loc{
util.CharacterCount(b.lines[end-1].data),
len(b.lines[end-1].runes),
end - 1,
},
[]byte{'\n'},
Expand All @@ -1155,7 +1155,7 @@ func (b *Buffer) MoveLinesDown(start int, end int) {
if start < 0 || start >= end || end >= len(b.lines) {
return
}
l := string(b.LineBytes(end))
l := b.LineString(end)
b.Insert(
Loc{0, start},
l+"\n",
Expand Down Expand Up @@ -1196,7 +1196,7 @@ func (b *Buffer) findMatchingBrace(braceType [2]rune, start Loc, char rune) (Loc
}
} else if char == braceType[1] {
for y := start.Y; y >= 0; y-- {
l := []rune(string(b.lines[y].data))
l := []rune(string(b.LineBytes(y)))
xInit := len(l) - 1
if y == start.Y {
xInit = start.X
Expand Down Expand Up @@ -1281,7 +1281,14 @@ func (b *Buffer) Retab() {
l = bytes.TrimLeft(l, " \t")

b.Lock()
b.lines[i].data = append(ws, l...)
ws = append(ws, l...)
var runes []Character
for len(ws) > 0 {
combc, s := util.DecodeCombinedCharacter(ws)
runes = append(runes, Character{combc})
ws = ws[s:]
}
b.lines[i].runes = runes
b.Unlock()

b.MarkModified(i, i)
Expand Down Expand Up @@ -1317,7 +1324,7 @@ func ParseCursorLocation(cursorPositions []string) (Loc, error) {

// Line returns the string representation of the given line number
func (b *Buffer) Line(i int) string {
return string(b.LineBytes(i))
return b.LineString(i)
}

func (b *Buffer) Write(bytes []byte) (n int, err error) {
Expand Down
17 changes: 3 additions & 14 deletions internal/buffer/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,24 +601,13 @@ func (c *Cursor) SubWordLeft() {

// RuneUnder returns the rune under the given x position
func (c *Cursor) RuneUnder(x int) rune {
line := c.buf.LineBytes(c.Y)
if len(line) == 0 || x >= util.CharacterCount(line) {
line := c.buf.LineCharacters(c.Y)
if len(line) == 0 || x >= len(line) {
return '\n'
} else if x < 0 {
x = 0
}
i := 0
for len(line) > 0 {
r, _, size := util.DecodeCharacter(line)
line = line[size:]

if i == x {
return r
}

i++
}
return '\n'
return line[x].combc[0]
}

func (c *Cursor) StoreVisualX() {
Expand Down
Loading