From dc6da7baa5be6ff39ed6ff9141b0c8bd446d8960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:50:45 +0200 Subject: [PATCH] buffer: Lock line modifications within `Retab()` --- internal/buffer/buffer.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 35e650fd05..6e0dea0886 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -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 { @@ -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 }