Fix scrolling BufferView past empty lines

This commit is contained in:
Josh Holtrop 2017-09-20 20:00:19 -04:00
parent d2fa28c5e1
commit 55dc13d729
2 changed files with 32 additions and 0 deletions

View File

@ -401,6 +401,7 @@ void BufferView::move_forward_to_screen_position(
std::shared_ptr<Buffer::Iterator> line, int target_row_offset, std::shared_ptr<Buffer::Iterator> line, int target_row_offset,
bool allow_eol) bool allow_eol)
{ {
*m_iterator = *line;
for (auto it = horiz_iter(line); it.is_valid(); it++) for (auto it = horiz_iter(line); it.is_valid(); it++)
{ {
if ((allow_eol || (!it.is_eol())) && if ((allow_eol || (!it.is_eol())) &&

View File

@ -22,6 +22,21 @@ static std::shared_ptr<Buffer> buffer1()
return std::make_shared<Buffer>((const uint8_t *)data, strlen(data)); return std::make_shared<Buffer>((const uint8_t *)data, strlen(data));
} }
static std::shared_ptr<Buffer> buffer2()
{
static const char data[] =
"0\n"
"\n"
"2\n"
"3\n"
"4\n"
"\n"
"6\n"
"7\n"
"8\n";
return std::make_shared<Buffer>((const uint8_t *)data, strlen(data));
}
static std::shared_ptr<Buffer> buffer_empty() static std::shared_ptr<Buffer> buffer_empty()
{ {
return std::make_shared<Buffer>(nullptr, 0u); return std::make_shared<Buffer>(nullptr, 0u);
@ -698,3 +713,19 @@ TEST(BufferViewTest, shows_only_lines_in_buffer_if_fewer_lines_in_buffer_than_vi
} }
EXPECT_EQ(13, count); EXPECT_EQ(13, count);
} }
TEST(BufferViewTest, scrolls_past_empty_lines)
{
auto b = buffer2();
auto iterator = b->add_cursor();
BufferView bv(b, iterator, Cwd);
bv.resize(10, 1);
bv.update();
EXPECT_EQ(0, LineNumber(iterator));
bv.scroll_view_down(3, false);
bv.update();
EXPECT_EQ(3, LineNumber(iterator));
bv.scroll_view_up(3, false);
bv.update();
EXPECT_EQ(0, LineNumber(iterator));
}