diff options
| author | Maxime Coste <mawww@kakoune.org> | 2020-03-20 20:26:05 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2020-03-20 20:27:50 +1100 |
| commit | 3c265acd6c9640676c9e976c1795c72daabe71e2 (patch) | |
| tree | bf5e4f7f473d7d8f94a1d33e9eb2a67324d6dc31 /src/buffer.cc | |
| parent | 401ef84a4bbba69a1ccf787712369a43253aa5bd (diff) | |
Remove posB from information given by the diff algorithm
posB is always the sum of previous add len and previous keep len,
so very easy to keep track of.
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index c2a04c2e..d84586cd 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -260,28 +260,31 @@ void Buffer::reload(StringView data, timespec fs_timestamp) Vector<Diff> diff; for_each_diff(m_lines.begin(), m_lines.size(), parsed_lines.lines.begin(), parsed_lines.lines.size(), - [&diff](DiffOp op, int len, int posB) - { diff.push_back({op, len, posB}); }, + [&diff](DiffOp op, int len) + { diff.push_back({op, len}); }, [](const StringDataPtr& lhs, const StringDataPtr& rhs) { return lhs->strview() == rhs->strview(); }); auto it = m_lines.begin(); + auto new_it = parsed_lines.lines.begin(); for (auto& d : diff) { if (d.op == DiffOp::Keep) + { it += d.len; + new_it += d.len; + } else if (d.op == DiffOp::Add) { const LineCount cur_line = (int)(it - m_lines.begin()); for (LineCount line = 0; line < d.len; ++line) - m_current_undo_group.push_back({ - Modification::Insert, cur_line + line, - parsed_lines.lines[(int)(d.posB + line)]}); + m_current_undo_group.push_back({Modification::Insert, cur_line + line, *(new_it + (int)line)}); - m_changes.push_back({ Change::Insert, cur_line, cur_line + d.len }); - m_lines.insert(it, parsed_lines.lines.begin() + d.posB, parsed_lines.lines.begin() + d.posB + d.len); + m_changes.push_back({Change::Insert, cur_line, cur_line + d.len}); + m_lines.insert(it, new_it, new_it + d.len); it = m_lines.begin() + (int)(cur_line + d.len); + new_it += d.len; } else if (d.op == DiffOp::Remove) { |
