applyDiff applies change from the other buffer to the buffer for given file name, from diff that includes given line.
(ab int, line int)
| 475 | // applyDiff applies change from the other buffer to the buffer for given file |
| 476 | // name, from diff that includes given line. |
| 477 | func (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. |
| 514 | func (dv *DiffEditor) undoDiff(ab int) error { |
no test coverage detected