From c32a7b9b74dfef609b27f3482a76b15329185e1a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 23 Nov 2012 18:42:07 +0100 Subject: Buffer takes a vector of lines as initial content --- src/buffer.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/buffer.cc') diff --git a/src/buffer.cc b/src/buffer.cc index ac0b8fce..78d89ce4 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -12,8 +12,7 @@ namespace Kakoune { -Buffer::Buffer(String name, Flags flags, - String initial_content) +Buffer::Buffer(String name, Flags flags, std::vector lines) : m_name(std::move(name)), m_flags(flags | Flags::NoUndo), m_history(), m_history_cursor(m_history.begin()), m_last_save_undo_index(0), @@ -22,9 +21,15 @@ Buffer::Buffer(String name, Flags flags, m_options(GlobalOptions::instance()) { BufferManager::instance().register_buffer(*this); - if (initial_content.empty() or initial_content.back() != '\n') - initial_content += '\n'; - do_insert(begin(), std::move(initial_content)); + + ByteCount pos = 0; + m_lines.reserve(lines.size()); + for (auto& line : lines) + { + assert(not line.empty() and line.back() == '\n'); + m_lines.emplace_back(Line{ pos, std::move(line) }); + pos += m_lines.back().length(); + } Editor editor_for_hooks(*this); Context context(editor_for_hooks); -- cgit v1.2.3