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

Method updateDiff

internal/buffer/buffer.go:1328–1373  ·  view source on GitHub ↗
(synchronous bool)

Source from the content-addressed store, hash-verified

1326}
1327
1328func (b *Buffer) updateDiff(synchronous bool) {
1329 b.diffLock.Lock()
1330 defer b.diffLock.Unlock()
1331
1332 b.diff = make(map[int]DiffStatus)
1333
1334 if b.diffBase == nil {
1335 return
1336 }
1337
1338 differ := dmp.New()
1339
1340 if !synchronous {
1341 b.Lock()
1342 }
1343 bytes := b.Bytes()
1344 if !synchronous {
1345 b.Unlock()
1346 }
1347
1348 baseRunes, bufferRunes, _ := differ.DiffLinesToRunes(string(b.diffBase), string(bytes))
1349 diffs := differ.DiffMainRunes(baseRunes, bufferRunes, false)
1350 lineN := 0
1351
1352 for _, diff := range diffs {
1353 lineCount := len([]rune(diff.Text))
1354
1355 switch diff.Type {
1356 case dmp.DiffEqual:
1357 lineN += lineCount
1358 case dmp.DiffInsert:
1359 var status DiffStatus
1360 if b.diff[lineN] == DSDeletedAbove {
1361 status = DSModified
1362 } else {
1363 status = DSAdded
1364 }
1365 for i := 0; i < lineCount; i++ {
1366 b.diff[lineN] = status
1367 lineN++
1368 }
1369 case dmp.DiffDelete:
1370 b.diff[lineN] = DSDeletedAbove
1371 }
1372 }
1373}
1374
1375// UpdateDiff computes the diff between the diff base and the buffer content.
1376// The update may be performed synchronously or asynchronously.

Callers 1

UpdateDiffMethod · 0.95

Calls 3

BytesMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected