Skip to content

Commit

Permalink
buffer: Lock line modifications within Retab()
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed Apr 5, 2024
1 parent 7c141ac commit dc6da7b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,14 @@ func (b *Buffer) Retab() {
tabsize := util.IntOpt(b.Settings["tabsize"])
dirty := false

for i := 0; i < b.LinesNum(); i++ {
l := b.LineBytes(i)
for i := 0; ; i++ {
b.Lock()
if i >= b.LinesNum() {
b.Unlock()
break
}

l := b.LineBytes(i)
ws := util.GetLeadingWhitespace(l)
if len(ws) != 0 {
if toSpaces {
Expand All @@ -1181,6 +1186,8 @@ func (b *Buffer) Retab() {

l = bytes.TrimLeft(l, " \t")
b.lines[i].data = append(ws, l...)
b.Unlock()

b.MarkModified(i, i)
dirty = true
}
Expand Down

0 comments on commit dc6da7b

Please sign in to comment.