~kiwec/ke

38565e0889027412649f15be875fd3abe5d0e643 — kiwec 3 years ago 4a93bec
Fix crash on launch

Still crashes while editing
6 files changed, 25 insertions(+), 18 deletions(-)

M src/Buffer.hpp
M src/Document.cpp
M src/Document.hpp
M src/Event.cpp
M src/Syntax.cpp
M src/Syntax.hpp
M src/Buffer.hpp => src/Buffer.hpp +4 -5
@@ 16,7 16,10 @@ class Buffer : public File, public InputHandler {
private:
	/// First visible line number, starts at 1 (just like the gutter)
	/// If the user scrolled down, this number will be higher
	uint m_first_visible_line_nb;
	uint m_first_visible_line_nb = 1;

	/// Currently selected line number - starts at 1
	uint current_line_nb = 1;

	/// Dimensions of the buffer on the screen
	Canvas m_canvas;


@@ 24,9 27,6 @@ private:
	/// Event history - contains undo/redo events
	History m_history;

	/// Currently selected line number - starts at 1
	uint current_line_nb;

	Editable selected_line;

public:


@@ 36,7 36,6 @@ public:
		m_canvas = Canvas{ 0, 0, tb_width(), tb_height() };

		// Scroll to the end of the file
		m_first_visible_line_nb = 1;
		scroll(1);

		// Go to end of the line

M src/Document.cpp => src/Document.cpp +5 -2
@@ 16,10 16,13 @@ Line Text::get_line(uint line_number) {
}

Line Text::get_line(Line closest, uint wanted_line_number) {
	while(closest.number() > wanted_line_number) {
	assert(wanted_line_number > 0);
	assert(wanted_line_number <= nb_lines);
	
	while(closest.number() < wanted_line_number) {
		closest = closest.next();
	}
	while(closest.number() < wanted_line_number) {
	while(closest.number() > wanted_line_number) {
		closest = closest.prev();
	}
	return closest;

M src/Document.hpp => src/Document.hpp +2 -2
@@ 45,7 45,7 @@ public:
	}

	T& operator[](uint pos) const {
		assert(pos < m_size);
		assert(pos <= m_size);
		return m_data[pos];
	}



@@ 152,7 152,7 @@ public:
		// Insert data
		Data::insert(inserted_data, data_size, pos);

		// Update syntax
		// Resize syntax
		auto zeroes = new syntax_t[data_size]();
		m_syntax.insert(zeroes, data_size, pos);
		delete[] zeroes;

M src/Event.cpp => src/Event.cpp +1 -1
@@ 22,7 22,7 @@ void WriteEvent::erase(Buffer& buf) {
	buf.move_to(line);
	buf.set_x(pos);

	for(auto ptr = text; *text != L'\0'; text++) {
	for(auto ptr = text; *ptr != L'\0'; ptr++) {
		if(erase_forwards) {
			buf.erase_forwards(false);
		} else {

M src/Syntax.cpp => src/Syntax.cpp +6 -8
@@ 54,11 54,6 @@ static const std::wstring operators[] = {

static constexpr uint operators_size = std::extent<decltype(operators)>::value;

static constexpr uint CHAR_COLOR = 1;
static constexpr uint COMMENT_COLOR = 2;
static constexpr uint STRING_COLOR = 6;
static constexpr uint DEFAULT_COLOR = 15;

bool isAlpha(wchar_t c) {
	const std::wstring letters = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	return letters.find(c) != std::string::npos;


@@ 277,15 272,18 @@ void Syntax::MarkStartCommented(Line* line) {
*/

void Syntax::update(Text& text) {
	Line line = text.get_line(0);
	for(; line.number() <= text.get_nb_lines(); line = line.next()) {
	Line line = text.get_line(1);
	for(;;) {
		update(line);
		if(line.is_last()) break;
		line = line.next();
	}
}

void Syntax::update(Line line) {
	prepare(line);
	if(line.length() == 0) return;

	prepare(line);
	markStrings(line);
	markChars(line);
	markComments(line);

M src/Syntax.hpp => src/Syntax.hpp +7 -0
@@ 7,6 7,13 @@ class Line;
class Text;
struct Section;

enum TextColor {
	CHAR_COLOR = 1,
	COMMENT_COLOR = 2,
	STRING_COLOR = 6,
	DEFAULT_COLOR = 15,
};

class Syntax {
private:
	static void prepare(Line);