MCPcopy
hub / github.com/micro-editor/micro / UpdateDiff

Method UpdateDiff

internal/buffer/buffer.go:1379–1403  ·  view source on GitHub ↗

UpdateDiff computes the diff between the diff base and the buffer content. The update may be performed synchronously or asynchronously. If an asynchronous update is already pending when UpdateDiff is called, UpdateDiff does not schedule another update.

()

Source from the content-addressed store, hash-verified

1377// If an asynchronous update is already pending when UpdateDiff is called,
1378// UpdateDiff does not schedule another update.
1379func (b *Buffer) UpdateDiff() {
1380 if b.updateDiffTimer != nil {
1381 return
1382 }
1383
1384 lineCount := b.LinesNum()
1385 if b.diffBaseLineCount > lineCount {
1386 lineCount = b.diffBaseLineCount
1387 }
1388
1389 if lineCount < 1000 {
1390 b.updateDiff(true)
1391 } else if lineCount < 30000 {
1392 b.updateDiffTimer = time.AfterFunc(500*time.Millisecond, func() {
1393 b.updateDiffTimer = nil
1394 b.updateDiff(false)
1395 screen.Redraw()
1396 })
1397 } else {
1398 // Don't compute diffs for very large files
1399 b.diffLock.Lock()
1400 b.diff = make(map[int]DiffStatus)
1401 b.diffLock.Unlock()
1402 }
1403}
1404
1405// SetDiffBase sets the text that is used as the base for diffing the buffer content
1406func (b *Buffer) SetDiffBase(diffBase []byte) {

Callers 3

SetDiffBaseMethod · 0.95
displayBufferMethod · 0.80
ToggleDiffGutterMethod · 0.80

Calls 5

updateDiffMethod · 0.95
RedrawFunction · 0.92
LinesNumMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected