~kiwec/ke

a73044b015189bfadeae1291cad4b0037ea39129 — Wolf Clément 3 years ago 337ac6f
Fix prev() crash when first line empty
3 files changed, 8 insertions(+), 5 deletions(-)

M src/Line.cpp
D test/tests.d
D test/tests.o
M src/Line.cpp => src/Line.cpp +8 -3
@@ 51,10 51,15 @@ Line Line::next() const {
Line Line::prev() const {
	assert(!is_first());

	auto offset = -2;
	// Edge case : first line is empty and we are the second line
	if(m_start == 1) {
		return Line(m_doc, 0, m_number - 1);
	}

	uint offset = 2;
	auto ptr = begin();
	for(; m_start + offset > 0 && ptr[offset] != L'\n'; offset--);
	return Line(m_doc, m_start + offset, m_number - 1);
	for(; m_start - offset > 0 && *(ptr - offset) != L'\n'; offset++);
	return Line(m_doc, m_start - offset, m_number - 1);
}

Line Line::make_next() {

D test/tests.d => test/tests.d +0 -2
@@ 1,2 0,0 @@
test/tests.o: test/tests.cpp test/acutest.h test/../src/Document.hpp \
  test/../src/Syntax.hpp test/../src/Line.hpp

D test/tests.o => test/tests.o +0 -0