MCPcopy Create free account
hub / github.com/cogentcore/core / applyDiff

Method applyDiff

texteditor/diffeditor.go:477–511  ·  view source on GitHub ↗

applyDiff applies change from the other buffer to the buffer for given file name, from diff that includes given line.

(ab int, line int)

Source from the content-addressed store, hash-verified

475// applyDiff applies change from the other buffer to the buffer for given file
476// name, from diff that includes given line.
477func (dv *DiffEditor) applyDiff(ab int, line int) bool {
478 tva, tvb := dv.textEditors()
479 tv := tva
480 if ab == 1 {
481 tv = tvb
482 }
483 if line < 0 {
484 line = tv.CursorPos.Ln
485 }
486 di, df := dv.alignD.DiffForLine(line)
487 if di < 0 || df.Tag == 'e' {
488 return false
489 }
490
491 if ab == 0 {
492 dv.bufferA.Undos.Off = false
493 // srcLen := len(dv.BufB.Lines[df.J2])
494 spos := lexer.Pos{Ln: df.I1, Ch: 0}
495 epos := lexer.Pos{Ln: df.I2, Ch: 0}
496 src := dv.bufferB.Region(spos, epos)
497 dv.bufferA.DeleteText(spos, epos, true)
498 dv.bufferA.insertText(spos, src.ToBytes(), true) // we always just copy, is blank for delete..
499 dv.diffs.BtoA(di)
500 } else {
501 dv.bufferB.Undos.Off = false
502 spos := lexer.Pos{Ln: df.J1, Ch: 0}
503 epos := lexer.Pos{Ln: df.J2, Ch: 0}
504 src := dv.bufferA.Region(spos, epos)
505 dv.bufferB.DeleteText(spos, epos, true)
506 dv.bufferB.insertText(spos, src.ToBytes(), true)
507 dv.diffs.AtoB(di)
508 }
509 dv.updateToolbar()
510 return true
511}
512
513// undoDiff undoes last applied change, if any.
514func (dv *DiffEditor) undoDiff(ab int) error {

Callers 2

MakeToolbarMethod · 0.95
InitMethod · 0.80

Calls 9

textEditorsMethod · 0.95
updateToolbarMethod · 0.95
DiffForLineMethod · 0.80
ToBytesMethod · 0.80
BtoAMethod · 0.80
AtoBMethod · 0.80
RegionMethod · 0.45
DeleteTextMethod · 0.45
insertTextMethod · 0.45

Tested by

no test coverage detected