diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-11-23 18:42:07 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-11-23 18:42:07 +0100 |
| commit | c32a7b9b74dfef609b27f3482a76b15329185e1a (patch) | |
| tree | d659dd7cf1675f6b154fd4c74f2fc80bb20f5092 /src/buffer.cc | |
| parent | 53be5c87d2012eeb23fda75ba5ca2051cc3c29a6 (diff) | |
Buffer takes a vector of lines as initial content
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 15 |
1 files changed, 10 insertions, 5 deletions
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<String> 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); |
