Example #1
0
func minUpdate(v *nvim.Nvim, b nvim.Buffer, in [][]byte, out [][]byte) error {

	// Find matching head lines.

	n := len(out)
	if len(in) < len(out) {
		n = len(in)
	}
	head := 0
	for ; head < n; head++ {
		if !bytes.Equal(in[head], out[head]) {
			break
		}
	}

	// Nothing to do?

	if head == len(in) && head == len(out) {
		return nil
	}

	// Find matching tail lines.

	n -= head
	tail := 0
	for ; tail < n; tail++ {
		if !bytes.Equal(in[len(in)-tail-1], out[len(out)-tail-1]) {
			break
		}
	}

	// Update the buffer.

	start := head
	end := len(in) - tail
	repl := out[head : len(out)-tail]
	return v.SetBufferLines(b, start, end, true, repl)
}