summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index c0e25f0a..f56d5d2e 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -344,10 +344,10 @@ ByteCoord Buffer::do_insert(ByteCoord pos, StringView content)
ByteCoord begin;
ByteCoord end;
- bool at_end = false;
+ const bool at_end = is_end(pos);
// if we inserted at the end of the buffer, we have created a new
// line without inserting a '\n'
- if (is_end(pos))
+ if (at_end)
{
ByteCount start = 0;
for (ByteCount i = 0; i < content.length(); ++i)
@@ -363,7 +363,6 @@ ByteCoord Buffer::do_insert(ByteCoord pos, StringView content)
begin = pos.column == 0 ? pos : ByteCoord{ pos.line + 1, 0 };
end = ByteCoord{ line_count(), 0 };
- at_end = true;
}
else
{
@@ -377,20 +376,15 @@ ByteCoord Buffer::do_insert(ByteCoord pos, StringView content)
{
if (content[i] == '\n')
{
- StringView line_content = content.substr(start, i + 1 - start);
- if (start == 0)
- new_lines.emplace_back(StringData::create(prefix + line_content));
- else
- new_lines.push_back(StringData::create(line_content));
+ StringView line = content.substr(start, i + 1 - start);
+ new_lines.push_back(StringData::create(start == 0 ? prefix + line : line));
start = i + 1;
}
}
if (start == 0)
- new_lines.emplace_back(StringData::create(prefix + content + suffix));
+ new_lines.push_back(StringData::create(prefix + content + suffix));
else if (start != content.length() or not suffix.empty())
- new_lines.emplace_back(StringData::create(content.substr(start) + suffix));
-
- LineCount last_line = pos.line + new_lines.size() - 1;
+ new_lines.push_back(StringData::create(content.substr(start) + suffix));
auto line_it = m_lines.begin() + (int)pos.line;
*line_it = std::move(*new_lines.begin());
@@ -399,6 +393,7 @@ ByteCoord Buffer::do_insert(ByteCoord pos, StringView content)
std::make_move_iterator(new_lines.end()));
begin = pos;
+ const LineCount last_line = pos.line + new_lines.size() - 1;
end = ByteCoord{ last_line, m_lines[last_line].length() - suffix.length() };
}