@@ -1280,7 +1280,7 @@ func (b *Buffer) Write(bytes []byte) (n int, err error) {
12801280 return len (bytes ), nil
12811281}
12821282
1283- func (b * Buffer ) updateDiffSync ( ) {
1283+ func (b * Buffer ) updateDiff ( synchronous bool ) {
12841284 b .diffLock .Lock ()
12851285 defer b .diffLock .Unlock ()
12861286
@@ -1291,7 +1291,16 @@ func (b *Buffer) updateDiffSync() {
12911291 }
12921292
12931293 differ := dmp .New ()
1294- baseRunes , bufferRunes , _ := differ .DiffLinesToRunes (string (b .diffBase ), string (b .Bytes ()))
1294+
1295+ if ! synchronous {
1296+ b .Lock ()
1297+ }
1298+ bytes := b .Bytes ()
1299+ if ! synchronous {
1300+ b .Unlock ()
1301+ }
1302+
1303+ baseRunes , bufferRunes , _ := differ .DiffLinesToRunes (string (b .diffBase ), string (bytes ))
12951304 diffs := differ .DiffMainRunes (baseRunes , bufferRunes , false )
12961305 lineN := 0
12971306
@@ -1320,13 +1329,9 @@ func (b *Buffer) updateDiffSync() {
13201329
13211330// UpdateDiff computes the diff between the diff base and the buffer content.
13221331// The update may be performed synchronously or asynchronously.
1323- // UpdateDiff calls the supplied callback when the update is complete.
1324- // The argument passed to the callback is set to true if and only if
1325- // the update was performed synchronously.
13261332// If an asynchronous update is already pending when UpdateDiff is called,
1327- // UpdateDiff does not schedule another update, in which case the callback
1328- // is not called.
1329- func (b * Buffer ) UpdateDiff (callback func (bool )) {
1333+ // UpdateDiff does not schedule another update.
1334+ func (b * Buffer ) UpdateDiff () {
13301335 if b .updateDiffTimer != nil {
13311336 return
13321337 }
@@ -1337,20 +1342,18 @@ func (b *Buffer) UpdateDiff(callback func(bool)) {
13371342 }
13381343
13391344 if lineCount < 1000 {
1340- b .updateDiffSync ()
1341- callback (true )
1345+ b .updateDiff (true )
13421346 } else if lineCount < 30000 {
13431347 b .updateDiffTimer = time .AfterFunc (500 * time .Millisecond , func () {
13441348 b .updateDiffTimer = nil
1345- b .updateDiffSync ( )
1346- callback ( false )
1349+ b .updateDiff ( false )
1350+ screen . Redraw ( )
13471351 })
13481352 } else {
13491353 // Don't compute diffs for very large files
13501354 b .diffLock .Lock ()
13511355 b .diff = make (map [int ]DiffStatus )
13521356 b .diffLock .Unlock ()
1353- callback (true )
13541357 }
13551358}
13561359
@@ -1362,9 +1365,7 @@ func (b *Buffer) SetDiffBase(diffBase []byte) {
13621365 } else {
13631366 b .diffBaseLineCount = strings .Count (string (diffBase ), "\n " )
13641367 }
1365- b .UpdateDiff (func (synchronous bool ) {
1366- screen .Redraw ()
1367- })
1368+ b .UpdateDiff ()
13681369}
13691370
13701371// DiffStatus returns the diff status for a line in the buffer
0 commit comments