Small improvements
This commit is contained in:
@@ -39,6 +39,14 @@ struct Edit {
|
|||||||
String string;
|
String string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Cursor {
|
||||||
|
union {
|
||||||
|
Range range;
|
||||||
|
int64_t pos[2];
|
||||||
|
};
|
||||||
|
int64_t ifront;
|
||||||
|
};
|
||||||
|
|
||||||
// - Buffer should be initialized before use!
|
// - Buffer should be initialized before use!
|
||||||
struct Buffer {
|
struct Buffer {
|
||||||
Allocator allocator;
|
Allocator allocator;
|
||||||
@@ -83,6 +91,43 @@ Range MakeRange(int64_t a, int64_t b) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t GetFront(Cursor cursor) {
|
||||||
|
int64_t result = cursor.pos[cursor.ifront];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t GetBack(Cursor cursor) {
|
||||||
|
int64_t index = (cursor.ifront + 1) % 2;
|
||||||
|
int64_t result = cursor.pos[index];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor MakeCursor(int64_t front, int64_t back) {
|
||||||
|
Cursor result = {};
|
||||||
|
if (front >= back) {
|
||||||
|
result.range.min = back;
|
||||||
|
result.range.max = front;
|
||||||
|
result.ifront = 1;
|
||||||
|
} else {
|
||||||
|
result.range.min = front;
|
||||||
|
result.range.max = back;
|
||||||
|
result.ifront = 0;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor ChangeBack(Cursor cursor, int64_t back) {
|
||||||
|
int64_t front = GetFront(cursor);
|
||||||
|
Cursor result = MakeCursor(front, back);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor ChangeFront(Cursor cursor, int64_t front) {
|
||||||
|
int64_t back = GetBack(cursor);
|
||||||
|
Cursor result = MakeCursor(front, back);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void AddEdit(Array<Edit> *edits, Range range, String string) {
|
void AddEdit(Array<Edit> *edits, Range range, String string) {
|
||||||
edits->add({range, string});
|
edits->add({range, string});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,51 +12,6 @@
|
|||||||
// WindowBuffer units
|
// WindowBuffer units
|
||||||
// WindowBufferWorld units
|
// WindowBufferWorld units
|
||||||
|
|
||||||
struct Cursor {
|
|
||||||
union {
|
|
||||||
Range range;
|
|
||||||
int64_t pos[2];
|
|
||||||
};
|
|
||||||
int64_t ifront;
|
|
||||||
};
|
|
||||||
|
|
||||||
int64_t GetFront(Cursor cursor) {
|
|
||||||
int64_t result = cursor.pos[cursor.ifront];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t GetBack(Cursor cursor) {
|
|
||||||
int64_t index = (cursor.ifront + 1) % 2;
|
|
||||||
int64_t result = cursor.pos[index];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cursor MakeCursor(int64_t front, int64_t back) {
|
|
||||||
Cursor result = {};
|
|
||||||
if (front >= back) {
|
|
||||||
result.range.min = back;
|
|
||||||
result.range.max = front;
|
|
||||||
result.ifront = 1;
|
|
||||||
} else {
|
|
||||||
result.range.min = front;
|
|
||||||
result.range.max = back;
|
|
||||||
result.ifront = 0;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cursor ChangeBack(Cursor cursor, int64_t back) {
|
|
||||||
int64_t front = GetFront(cursor);
|
|
||||||
Cursor result = MakeCursor(front, back);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cursor ChangeFront(Cursor cursor, int64_t front) {
|
|
||||||
int64_t back = GetBack(cursor);
|
|
||||||
Cursor result = MakeCursor(front, back);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Window {
|
struct Window {
|
||||||
uint64_t flags;
|
uint64_t flags;
|
||||||
Rect2 rect_in_world_units;
|
Rect2 rect_in_world_units;
|
||||||
@@ -155,7 +110,17 @@ void UpdateCursorsAfterEdit(Window *window, Array<Edit> edits) {
|
|||||||
int64_t offset = insert_size - remove_size;
|
int64_t offset = insert_size - remove_size;
|
||||||
|
|
||||||
ForItem(cursor, window->cursors) {
|
ForItem(cursor, window->cursors) {
|
||||||
if (edit.range.min <= cursor.range.min) {
|
if (edit.range.min == cursor.range.min) {
|
||||||
|
if (GetRangeSize(edit.range)) {
|
||||||
|
cursor.range.min += edit.string.len;
|
||||||
|
} else {
|
||||||
|
cursor.range.min += offset;
|
||||||
|
}
|
||||||
|
cursor.range.max = cursor.range.min;
|
||||||
|
} else if (edit.range.min <= cursor.range.min) {
|
||||||
|
if (GetRangeSize(edit.range)) {
|
||||||
|
cursor.range.min += edit.string.len;
|
||||||
|
}
|
||||||
cursor.range.min += offset;
|
cursor.range.min += offset;
|
||||||
cursor.range.max = cursor.range.min;
|
cursor.range.max = cursor.range.min;
|
||||||
}
|
}
|
||||||
@@ -203,8 +168,10 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.cursors.add({});
|
window.cursors.add({});
|
||||||
int64_t pos = GetLine(window.buffer, 1).range.min;
|
for (int i = 1; i < 10; i += 1) {
|
||||||
window.cursors.add({pos, pos});
|
Line line = GetLine(window.buffer, i);
|
||||||
|
window.cursors.add({line.range.min, line.range.min});
|
||||||
|
}
|
||||||
windows.add(window);
|
windows.add(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,26 +194,38 @@ int main() {
|
|||||||
it.range.max = it.range.min = Seek(focused_window->buffer, it.range.min, ITERATE_BACKWARD);
|
it.range.max = it.range.min = Seek(focused_window->buffer, it.range.min, ITERATE_BACKWARD);
|
||||||
} else {
|
} else {
|
||||||
if (IsKeyDown(KEY_LEFT_SHIFT)) {
|
if (IsKeyDown(KEY_LEFT_SHIFT)) {
|
||||||
it.range.min = MoveLeft(focused_window->buffer, it.range.min);
|
int64_t front = GetFront(it);
|
||||||
|
front = MoveLeft(focused_window->buffer, front);
|
||||||
|
it = ChangeFront(it, front);
|
||||||
|
} else {
|
||||||
|
if (GetRangeSize(it.range) != 0) {
|
||||||
|
it.range.max = it.range.min;
|
||||||
} else {
|
} else {
|
||||||
it.range.max = it.range.min = MoveLeft(focused_window->buffer, it.range.min);
|
it.range.max = it.range.min = MoveLeft(focused_window->buffer, it.range.min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (IsKeyPressed(KEY_RIGHT) || IsKeyPressedRepeat(KEY_RIGHT)) {
|
if (IsKeyPressed(KEY_RIGHT) || IsKeyPressedRepeat(KEY_RIGHT)) {
|
||||||
For(focused_window->cursors) {
|
For(focused_window->cursors) {
|
||||||
if (IsKeyDown(KEY_LEFT_CONTROL)) {
|
if (IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||||
it.range.max = it.range.min = Seek(focused_window->buffer, it.range.min, ITERATE_FORWARD);
|
it.range.max = it.range.min = Seek(focused_window->buffer, it.range.min, ITERATE_FORWARD);
|
||||||
} else {
|
} else {
|
||||||
if (IsKeyDown(KEY_LEFT_SHIFT)) {
|
if (IsKeyDown(KEY_LEFT_SHIFT)) {
|
||||||
it.range.max = MoveRight(focused_window->buffer, it.range.max);
|
int64_t front = GetFront(it);
|
||||||
|
front = MoveRight(focused_window->buffer, front);
|
||||||
|
it = ChangeFront(it, front);
|
||||||
|
} else {
|
||||||
|
if (GetRangeSize(it.range) != 0) {
|
||||||
|
it.range.min = it.range.max;
|
||||||
} else {
|
} else {
|
||||||
it.range.max = it.range.min = MoveRight(focused_window->buffer, it.range.min);
|
it.range.max = it.range.min = MoveRight(focused_window->buffer, it.range.min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) {
|
if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) {
|
||||||
For(focused_window->cursors) {
|
For(focused_window->cursors) {
|
||||||
it.range.max = it.range.min = MoveDown(focused_window->buffer, it.range.min);
|
it.range.max = it.range.min = MoveDown(focused_window->buffer, it.range.min);
|
||||||
|
|||||||
20
src/text_editor/ui_ideas.txt
Normal file
20
src/text_editor/ui_ideas.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
Buffer buffer;
|
||||||
|
Rect window_rect;
|
||||||
|
bool window_open = true;
|
||||||
|
|
||||||
|
if (window_open) {
|
||||||
|
Node *window_node = MakeBox(rect, GenerateID());
|
||||||
|
SetParent(window_node);
|
||||||
|
{
|
||||||
|
Node *close_button = Button("x");
|
||||||
|
if (close_button->left_clicked) {
|
||||||
|
window_open = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node *node = TextField(&buffer);
|
||||||
|
if (node->text_changed) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,12 +10,13 @@
|
|||||||
|
|
||||||
Arena Perm;
|
Arena Perm;
|
||||||
|
|
||||||
/* New threading model idea
|
/*
|
||||||
I could just spin up a bunch of threads and then
|
|
||||||
don't kill them. Just use them for searching! Each
|
|
||||||
one would have it's own xarena and so on.
|
|
||||||
|
|
||||||
|
|
||||||
|
TODO:
|
||||||
|
- New threading model idea: I could just spin up a bunch of threads and then don't kill them. Just use them for searching! Each one would have it's own xarena and so on.
|
||||||
|
- Improve scrolling
|
||||||
|
- Highlight selected line
|
||||||
|
- Improve the looks of the application
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct TimeString {
|
struct TimeString {
|
||||||
|
|||||||
Reference in New Issue
Block a user