Skip to content

Commit

Permalink
Import a simple text editor I started working on.
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Dec 3, 2018
1 parent 405383f commit ca6847b
Show file tree
Hide file tree
Showing 59 changed files with 895 additions and 39 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion AK/Bitmap.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "StdLib.h"
#include "StdLibExtras.h"
#include "Types.h"
#include "kmalloc.h"
#include "Assertions.h"
Expand Down
2 changes: 1 addition & 1 deletion AK/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Assertions.h"
#include "Retainable.h"
#include "RetainPtr.h"
#include "StdLib.h"
#include "StdLibExtras.h"
#include "kmalloc.h"

namespace AK {
Expand Down
2 changes: 1 addition & 1 deletion AK/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Buffer.h"
#include "Types.h"
#include "StdLib.h"
#include "StdLibExtras.h"

namespace AK {

Expand Down
2 changes: 1 addition & 1 deletion AK/DoublyLinkedList.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "StdLib.h"
#include "StdLibExtras.h"

namespace AK {

Expand Down
2 changes: 1 addition & 1 deletion AK/FileSystemPath.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "String.h"
#include "AKString.h"

namespace AK {

Expand Down
2 changes: 1 addition & 1 deletion AK/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "Assertions.h"
#include "OwnPtr.h"
#include "StdLib.h"
#include "StdLibExtras.h"

namespace AK {

Expand Down
2 changes: 1 addition & 1 deletion AK/HashMap.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "HashTable.h"
#include "StdLib.h"
#include "StdLibExtras.h"
#include "kstdio.h"

namespace AK {
Expand Down
2 changes: 1 addition & 1 deletion AK/HashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Assertions.h"
#include "DoublyLinkedList.h"
#include "Traits.h"
#include "StdLib.h"
#include "StdLibExtras.h"
#include "kstdio.h"

//#define HASHTABLE_DEBUG
Expand Down
2 changes: 1 addition & 1 deletion AK/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CXXFLAGS = -std=c++17 -O0 -W -Wall -ggdb3

all: $(PROGRAM)

test.o: Vector.h String.h StringImpl.h MappedFile.h HashTable.h SinglyLinkedList.h Traits.h HashMap.h TemporaryFile.h Buffer.h FileSystemPath.h StringBuilder.h
test.o: Vector.h AKString.h StringImpl.h MappedFile.h HashTable.h SinglyLinkedList.h Traits.h HashMap.h TemporaryFile.h Buffer.h FileSystemPath.h StringBuilder.h

.cpp.o:
$(CXX) $(CXXFLAGS) -o $@ -c $<
Expand Down
2 changes: 1 addition & 1 deletion AK/MappedFile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "String.h"
#include "AKString.h"

namespace AK {

Expand Down
6 changes: 6 additions & 0 deletions AK/Noncopyable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#define AK_MAKE_NONCOPYABLE(c) \
private: \
c(const c&) = delete; \
c& operator=(const c&) = delete;
2 changes: 1 addition & 1 deletion AK/OwnPtr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "StdLib.h"
#include "StdLibExtras.h"
#include "Types.h"
#include "Traits.h"

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions AK/String.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "String.h"
#include "StdLib.h"
#include "AKString.h"
#include "StdLibExtras.h"

namespace AK {

Expand Down
2 changes: 1 addition & 1 deletion AK/StringBuilder.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "String.h"
#include "AKString.h"
#include "Vector.h"

namespace AK {
Expand Down
2 changes: 1 addition & 1 deletion AK/StringImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "StringImpl.h"
#include "StdLib.h"
#include "StdLibExtras.h"
#include "kmalloc.h"

namespace AK {
Expand Down
2 changes: 1 addition & 1 deletion AK/TemporaryFile.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "String.h"
#include "AKString.h"
#include <stdio.h>

namespace AK {
Expand Down
2 changes: 1 addition & 1 deletion AK/test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "String.h"
#include "AKString.h"
//#include "StringBuilder.h"
#include "Vector.h"
#include <stdio.h>
Expand Down
46 changes: 46 additions & 0 deletions Editor/Document.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "Document.h"
#include "FileReader.h"

OwnPtr<Document> Document::create_from_file(const std::string& path)
{
auto document = make<Document>();

FileReader reader(path);
while (reader.can_read()) {
auto line = reader.read_line();
document->m_lines.push_back(Line(line));
}

return document;
}

void Document::dump()
{
fprintf(stderr, "Document{%p}\n", this);
for (size_t i = 0; i < m_lines.size(); ++i) {
fprintf(stderr, "[%02zu] %s\n", i, m_lines[i].data().c_str());
}
}

bool Document::backspace_at(Position position)
{
return false;
}

bool Document::insert_at(Position position, const std::string& text)
{
static FILE* f = fopen("log", "a");
fprintf(f, "@%zu,%zu: +%s\n", position.line(), position.column(), text.c_str());
fflush(f);
ASSERT(position.is_valid());
if (!position.is_valid())
return false;
ASSERT(position.line() < line_count());
if (position.line() >= line_count())
return false;
Line& line = m_lines[position.line()];
if (position.column() > line.length())
return false;
line.insert(position.column(), text);
return true;
}
27 changes: 27 additions & 0 deletions Editor/Document.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "cuki.h"
#include "Line.h"
#include "Position.h"
#include "OwnPtr.h"
#include <string>

class Document {
public:
Document() { }
~Document() { }

const std::deque<Line>& lines() const { return m_lines; }
std::deque<Line>& lines() { return m_lines; }
size_t line_count() const { return m_lines.size(); }

static OwnPtr<Document> create_from_file(const std::string& path);

bool insert_at(Position, const std::string&);
bool backspace_at(Position);

void dump();

private:
std::deque<Line> m_lines;
};
Loading

0 comments on commit ca6847b

Please sign in to comment.