forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import a simple text editor I started working on.
- Loading branch information
1 parent
405383f
commit ca6847b
Showing
59 changed files
with
895 additions
and
39 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
#include "Buffer.h" | ||
#include "Types.h" | ||
#include "StdLib.h" | ||
#include "StdLibExtras.h" | ||
|
||
namespace AK { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include "StdLib.h" | ||
#include "StdLibExtras.h" | ||
|
||
namespace AK { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include "String.h" | ||
#include "AKString.h" | ||
|
||
namespace AK { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#pragma once | ||
|
||
#include "String.h" | ||
#include "AKString.h" | ||
|
||
namespace AK { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
Oops, something went wrong.