Small improvements
This commit is contained in:
@@ -39,6 +39,14 @@ struct Edit {
|
||||
String string;
|
||||
};
|
||||
|
||||
struct Cursor {
|
||||
union {
|
||||
Range range;
|
||||
int64_t pos[2];
|
||||
};
|
||||
int64_t ifront;
|
||||
};
|
||||
|
||||
// - Buffer should be initialized before use!
|
||||
struct Buffer {
|
||||
Allocator allocator;
|
||||
@@ -83,6 +91,43 @@ Range MakeRange(int64_t a, int64_t b) {
|
||||
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) {
|
||||
edits->add({range, string});
|
||||
}
|
||||
|
||||
@@ -12,51 +12,6 @@
|
||||
// WindowBuffer 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 {
|
||||
uint64_t flags;
|
||||
Rect2 rect_in_world_units;
|
||||
@@ -155,7 +110,17 @@ void UpdateCursorsAfterEdit(Window *window, Array<Edit> edits) {
|
||||
int64_t offset = insert_size - remove_size;
|
||||
|
||||
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.max = cursor.range.min;
|
||||
}
|
||||
@@ -203,8 +168,10 @@ int main() {
|
||||
}
|
||||
|
||||
window.cursors.add({});
|
||||
int64_t pos = GetLine(window.buffer, 1).range.min;
|
||||
window.cursors.add({pos, pos});
|
||||
for (int i = 1; i < 10; i += 1) {
|
||||
Line line = GetLine(window.buffer, i);
|
||||
window.cursors.add({line.range.min, line.range.min});
|
||||
}
|
||||
windows.add(window);
|
||||
}
|
||||
|
||||
@@ -227,9 +194,15 @@ int main() {
|
||||
it.range.max = it.range.min = Seek(focused_window->buffer, it.range.min, ITERATE_BACKWARD);
|
||||
} else {
|
||||
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 {
|
||||
it.range.max = it.range.min = MoveLeft(focused_window->buffer, it.range.min);
|
||||
if (GetRangeSize(it.range) != 0) {
|
||||
it.range.max = it.range.min;
|
||||
} else {
|
||||
it.range.max = it.range.min = MoveLeft(focused_window->buffer, it.range.min);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,9 +213,15 @@ int main() {
|
||||
it.range.max = it.range.min = Seek(focused_window->buffer, it.range.min, ITERATE_FORWARD);
|
||||
} else {
|
||||
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 {
|
||||
it.range.max = it.range.min = MoveRight(focused_window->buffer, it.range.min);
|
||||
if (GetRangeSize(it.range) != 0) {
|
||||
it.range.min = it.range.max;
|
||||
} else {
|
||||
it.range.max = it.range.min = MoveRight(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;
|
||||
|
||||
/* 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 {
|
||||
|
||||
Reference in New Issue
Block a user