This commit is contained in:
Krzosa Karol
2024-07-22 15:35:22 +02:00
parent b1c123977d
commit 06082f2273
3 changed files with 46 additions and 3 deletions

View File

@@ -74,3 +74,32 @@ String16 Merge(Allocator allocator, Array<String16> list, String16 separator = "
string.data[size] = 0;
return string;
}
bool Seek(String16 string, String16 find, int64_t *index_out = NULL, SeekFlag flags = SeekFlag_None) {
bool ignore_case = flags & SeekFlag_IgnoreCase ? true : false;
bool result = false;
if (flags & SeekFlag_MatchFindLast) {
for (int64_t i = string.len; i != 0; i--) {
int64_t index = i - 1;
String16 substring = GetSlice(string, index, index + find.len);
if (AreEqual(substring, find, ignore_case)) {
if (index_out)
*index_out = index;
result = true;
break;
}
}
} else {
for (int64_t i = 0; i < string.len; i++) {
String16 substring = GetSlice(string, i, i + find.len);
if (AreEqual(substring, find, ignore_case)) {
if (index_out)
*index_out = i;
result = true;
break;
}
}
}
return result;
}

View File

@@ -31,7 +31,6 @@ Font MenuFont;
/*
- Ctrl + D - create new cursor at next occurence of word
- Line numbers
- Colored strings
- file dock on left side
@@ -78,10 +77,10 @@ int main(void) {
Add(&view.carets, {0, 0});
view.buffer = CreateBuffer(Perm);
// LoadUnicode(view.buffer);
LoadBigTextAndBigLine(view.buffer);
// LoadBigTextAndBigLine(view.buffer);
// LoadBigLine(view.buffer);
// LoadBigText(view.buffer);
// LoadTextA(view.buffer);
LoadTextA(view.buffer);
// LoadLine(view.buffer);
}

View File

@@ -216,6 +216,21 @@ void HandleKeybindings(View *_view) {
}
}
if (CtrlPress(KEY_D)) {
Range range = view.carets[0].range;
String16 string = GetString(buf, range);
String16 buffer = GetString(buf, {range.max, INT64_MAX});
Int index = 0;
if (Seek(buffer, string, &index)) {
Insert(&view.carets, MakeCaret(range.max + index, range.max + index + string.len), 0);
} else {
String16 buffer = GetString(buf);
if (Seek(buffer, string, &index)) {
Insert(&view.carets, MakeCaret(index, index + string.len), 0);
}
}
}
if (CtrlShiftPress(KEY_Z)) {
RedoEdit(&buf, &view.carets);
} else if (CtrlPress(KEY_Z)) {