Skip to content

Commit b4b21f9

Browse files
committed
Fix race condition in HandleRender
Move SetContentLineCount into OverwriteLinesAndClearEverythingElse. Calling it separately beforehand is not concurrency safe; we need both to happen when the view's writeMutex is locked.
1 parent e1a8327 commit b4b21f9

File tree

7 files changed

+12
-16
lines changed

7 files changed

+12
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/integrii/flaggy v1.4.0
1919
github.com/jesseduffield/generics v0.0.0-20250517122708-b0b4a53a6f5c
2020
github.com/jesseduffield/go-git/v5 v5.14.1-0.20250407170251-e1a013310ccd
21-
github.com/jesseduffield/gocui v0.3.1-0.20251223143206-950739ccd44a
21+
github.com/jesseduffield/gocui v0.3.1-0.20251223144240-29fe12e8d53f
2222
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5
2323
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
2424
github.com/karimkhaleel/jsonschema v0.0.0-20231001195015-d933f0d94ea3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ github.com/jesseduffield/generics v0.0.0-20250517122708-b0b4a53a6f5c h1:tC2Paiis
194194
github.com/jesseduffield/generics v0.0.0-20250517122708-b0b4a53a6f5c/go.mod h1:F2fEBk0ddf6ixrBrJjY7phfQ3hL9rXG0uSjvwYe50bE=
195195
github.com/jesseduffield/go-git/v5 v5.14.1-0.20250407170251-e1a013310ccd h1:ViKj6qth8FgcIWizn9KiACWwPemWSymx62OPN0tHT+Q=
196196
github.com/jesseduffield/go-git/v5 v5.14.1-0.20250407170251-e1a013310ccd/go.mod h1:lRhCiBr6XjQrvcQVa+UYsy/99d3wMXn/a0nSQlhnhlA=
197-
github.com/jesseduffield/gocui v0.3.1-0.20251223143206-950739ccd44a h1:XRsyqrSljes4TlaPczQViIAA4xqdnB0fKEEpZdqWWTA=
198-
github.com/jesseduffield/gocui v0.3.1-0.20251223143206-950739ccd44a/go.mod h1:sLIyZ2J42R6idGdtemZzsiR3xY5EF0KsvYEGh3dQv3s=
197+
github.com/jesseduffield/gocui v0.3.1-0.20251223144240-29fe12e8d53f h1:5ArylWehV98WTxJM7AcSa53YNskEFpHHv+VePONQn58=
198+
github.com/jesseduffield/gocui v0.3.1-0.20251223144240-29fe12e8d53f/go.mod h1:sLIyZ2J42R6idGdtemZzsiR3xY5EF0KsvYEGh3dQv3s=
199199
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY=
200200
github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5/go.mod h1:qxN4mHOAyeIDLP7IK7defgPClM/z1Kze8VVQiaEjzsQ=
201201
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=

pkg/gui/context/list_context_trait.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,9 @@ func (self *ListContextTrait) HandleRender() {
102102
if self.getNonModelItems != nil {
103103
totalLength += len(self.getNonModelItems())
104104
}
105-
self.GetViewTrait().SetContentLineCount(totalLength)
106105
startIdx, length := self.GetViewTrait().ViewPortYBounds()
107106
content := self.renderLines(startIdx, startIdx+length)
108-
self.GetViewTrait().SetViewPortContentAndClearEverythingElse(content)
107+
self.GetViewTrait().SetViewPortContentAndClearEverythingElse(totalLength, content)
109108
} else {
110109
content := self.renderLines(-1, -1)
111110
self.GetViewTrait().SetContent(content)

pkg/gui/context/view_trait.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,9 @@ func (self *ViewTrait) SetViewPortContent(content string) {
3434
self.view.OverwriteLines(y, content)
3535
}
3636

37-
func (self *ViewTrait) SetViewPortContentAndClearEverythingElse(content string) {
37+
func (self *ViewTrait) SetViewPortContentAndClearEverythingElse(lineCount int, content string) {
3838
_, y := self.view.Origin()
39-
self.view.OverwriteLinesAndClearEverythingElse(y, content)
40-
}
41-
42-
func (self *ViewTrait) SetContentLineCount(lineCount int) {
43-
self.view.SetContentLineCount(lineCount)
39+
self.view.OverwriteLinesAndClearEverythingElse(lineCount, y, content)
4440
}
4541

4642
func (self *ViewTrait) SetContent(content string) {

pkg/gui/types/context.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ type IViewTrait interface {
205205
SetRangeSelectStart(yIdx int)
206206
CancelRangeSelect()
207207
SetViewPortContent(content string)
208-
SetViewPortContentAndClearEverythingElse(content string)
209-
SetContentLineCount(lineCount int)
208+
SetViewPortContentAndClearEverythingElse(lineCount int, content string)
210209
SetContent(content string)
211210
SetFooter(value string)
212211
SetOriginX(value int)

vendor/github.com/jesseduffield/gocui/view.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame
221221
github.com/jesseduffield/go-git/v5/utils/merkletrie/noder
222222
github.com/jesseduffield/go-git/v5/utils/sync
223223
github.com/jesseduffield/go-git/v5/utils/trace
224-
# github.com/jesseduffield/gocui v0.3.1-0.20251223143206-950739ccd44a
224+
# github.com/jesseduffield/gocui v0.3.1-0.20251223144240-29fe12e8d53f
225225
## explicit; go 1.12
226226
github.com/jesseduffield/gocui
227227
# github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5

0 commit comments

Comments
 (0)