Port Seek word, add ctrl+left
This commit is contained in:
@@ -105,6 +105,21 @@ int64_t MoveUp(Buffer &buffer, int64_t pos) {
|
||||
return new_pos;
|
||||
}
|
||||
|
||||
void UpdateCursorsAfterEdit(Window *window, Array<Edit> edits) {
|
||||
ForItem(edit, edits) {
|
||||
int64_t remove_size = GetRangeSize(edit.range);
|
||||
int64_t insert_size = edit.string.len;
|
||||
int64_t offset = insert_size - remove_size;
|
||||
|
||||
ForItem(cursor, window->cursors) {
|
||||
if (edit.range.min <= cursor.min) {
|
||||
cursor.min += offset;
|
||||
cursor.max = cursor.min;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
InitScratch();
|
||||
RunBufferTests();
|
||||
@@ -168,7 +183,11 @@ int main() {
|
||||
}
|
||||
if (IsKeyPressed(KEY_RIGHT) || IsKeyPressedRepeat(KEY_RIGHT)) {
|
||||
For(focused_window->cursors) {
|
||||
it.max = it.min = MoveRight(focused_window->buffer, it.min);
|
||||
if (IsKeyDown(KEY_LEFT_CONTROL)) {
|
||||
it.max = it.min = Seek(focused_window->buffer, it.min, ITERATE_FORWARD);
|
||||
} else {
|
||||
it.max = it.min = MoveRight(focused_window->buffer, it.min);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) {
|
||||
@@ -196,8 +215,22 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle user input chars
|
||||
for (int c = GetCharPressed(); c; c = GetCharPressed()) {
|
||||
if (IsKeyPressed(KEY_BACKSPACE) || IsKeyPressedRepeat(KEY_BACKSPACE)) {
|
||||
Array<Edit> edits = {FrameArena};
|
||||
String string = {};
|
||||
For(focused_window->cursors) {
|
||||
int64_t pos = MoveLeft(focused_window->buffer, it.min);
|
||||
AddEdit(&edits, {pos, it.min}, string);
|
||||
}
|
||||
ApplyEdits(&focused_window->buffer, edits);
|
||||
UpdateCursorsAfterEdit(focused_window, edits);
|
||||
}
|
||||
|
||||
// Handle user input
|
||||
for (;;) {
|
||||
int c = GetCharPressed();
|
||||
if (!c) break;
|
||||
|
||||
String string = "?";
|
||||
UTF8Result utf8 = UTF32ToUTF8((uint32_t)c);
|
||||
if (utf8.error == 0) {
|
||||
@@ -209,19 +242,7 @@ int main() {
|
||||
AddEdit(&edits, it, string);
|
||||
}
|
||||
ApplyEdits(&focused_window->buffer, edits);
|
||||
|
||||
ForItem(edit, edits) {
|
||||
int64_t remove_size = GetRangeSize(edit.range);
|
||||
int64_t add_size = string.len;
|
||||
int64_t offset = add_size - remove_size;
|
||||
|
||||
ForItem(cursor, focused_window->cursors) {
|
||||
if (edit.range.min <= cursor.min) {
|
||||
cursor.min += offset;
|
||||
cursor.max = cursor.min;
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateCursorsAfterEdit(focused_window, edits);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user