diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-05-14 14:05:02 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-05-14 14:05:02 +0100 |
| commit | 8ba68044809d6fc0bc34eae44f7ff0a855463d1a (patch) | |
| tree | a718d5e179d9b5551fa1af3870122e6f12fbe67a /src/buffer.cc | |
| parent | cc97d4ba41169a3a365922b05a30fdab88dbe688 (diff) | |
Do not use diff when reloading a no undo buffer
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index cb0facee..be3ca7a2 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -167,44 +167,49 @@ void Buffer::reload(BufferLines lines, time_t fs_timestamp) commit_undo_group(); - auto diff = find_diff(m_lines.begin(), m_lines.size(), - lines.begin(), (int)lines.size(), - [](const StringDataPtr& lhs, const StringDataPtr& rhs) - { return lhs->strview() == rhs->strview(); }); + if (not record_undo) + { + m_changes.push_back({ Change::Erase, true, {0,0}, line_count() }); + + static_cast<BufferLines&>(m_lines) = std::move(lines); - auto it = m_lines.begin(); - for (auto& d : diff) + m_changes.push_back({ Change::Insert, true, {0,0}, line_count() }); + } + else { - switch (d.mode) + auto diff = find_diff(m_lines.begin(), m_lines.size(), + lines.begin(), (int)lines.size(), + [](const StringDataPtr& lhs, const StringDataPtr& rhs) + { return lhs->strview() == rhs->strview(); }); + + auto it = m_lines.begin(); + for (auto& d : diff) { - case Diff::Keep: it += d.len; break; - case Diff::Add: + if (d.mode == Diff::Keep) + it += d.len; + else if (d.mode == Diff::Add) { const LineCount cur_line = (int)(it - m_lines.begin()); - if (record_undo) - { - for (LineCount line = 0; line < d.len; ++line) - m_current_undo_group.emplace_back( - Modification::Insert, cur_line + line, - SharedString{lines[(int)(d.posB + line)]}); - } + + for (LineCount line = 0; line < d.len; ++line) + m_current_undo_group.emplace_back( + Modification::Insert, cur_line + line, + SharedString{lines[(int)(d.posB + line)]}); + m_changes.push_back({ Change::Insert, it == m_lines.end(), cur_line, cur_line + d.len }); it = m_lines.insert(it, &lines[d.posB], &lines[d.posB + d.len]) + d.len; - break; } - case Diff::Remove: + else if (d.mode == Diff::Remove) { const LineCount cur_line = (int)(it - m_lines.begin()); - if (record_undo) - { - for (LineCount line = d.len-1; line >= 0; --line) - m_current_undo_group.emplace_back( - Modification::Erase, cur_line + line, - SharedString{m_lines.get_storage(cur_line + line)}); - } + + for (LineCount line = d.len-1; line >= 0; --line) + m_current_undo_group.emplace_back( + Modification::Erase, cur_line + line, + SharedString{m_lines.get_storage(cur_line + line)}); + it = m_lines.erase(it, it + d.len); m_changes.push_back({ Change::Erase, it == m_lines.end(), cur_line, cur_line + d.len }); - break; } } } |
