Search back
This commit is contained in:
@@ -24,9 +24,8 @@ void AddCommonFlags(Array<S8_String> *cmd) {
|
|||||||
if (Profile == PROFILE_DEBUG) {
|
if (Profile == PROFILE_DEBUG) {
|
||||||
cmd->add("-DDEBUG_BUILD=1");
|
cmd->add("-DDEBUG_BUILD=1");
|
||||||
cmd->add("-DRELEASE_BUILD=0");
|
cmd->add("-DRELEASE_BUILD=0");
|
||||||
cmd->add("-fsanitize=address");
|
// cmd->add("-fsanitize=address");
|
||||||
cmd->add("-DUSE_ADDRESS_SANITIZER");
|
// cmd->add("-DUSE_ADDRESS_SANITIZER");
|
||||||
cmd->add("-D_DEBUG");
|
|
||||||
// cmd->add("/MDd");
|
// cmd->add("/MDd");
|
||||||
} else {
|
} else {
|
||||||
cmd->add("-DDEBUG_BUILD=0");
|
cmd->add("-DDEBUG_BUILD=0");
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ void MakeSureToUseSystemAllocator_SaveInClipboard(String16 string, Array<String1
|
|||||||
SavedClipboardCarets = caret_strings;
|
SavedClipboardCarets = caret_strings;
|
||||||
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
SDL_SetClipboardText(ToString(scratch, SavedClipboardString).data);
|
String string_to_save = ToString(scratch, SavedClipboardString).data;
|
||||||
|
SDL_SetClipboardText(string_to_save.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveStringInClipboard(String16 string) {
|
void SaveStringInClipboard(String16 string) {
|
||||||
|
|||||||
@@ -525,11 +525,29 @@ void MergeCarets(View *view) {
|
|||||||
Swap(&view->carets[first_caret_index], &view->carets[0]);
|
Swap(&view->carets[first_caret_index], &view->carets[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Caret FindInBuffer(Buffer *buffer, String16 needle, Caret caret, bool find_next = false) {
|
Caret FindPrev(Buffer *buffer, String16 needle, Caret caret) {
|
||||||
Int pos = caret.range.min;
|
Int pos = GetFront(caret);
|
||||||
|
String16 medium = GetString(*buffer, {0, pos});
|
||||||
|
|
||||||
|
Caret result = caret;
|
||||||
|
Int index = 0;
|
||||||
|
if (Seek(medium, needle, &index, SeekFlag_MatchFindLast)) {
|
||||||
|
result = MakeCaret(index, index + needle.len);
|
||||||
|
} else {
|
||||||
|
medium = GetString(*buffer);
|
||||||
|
if (Seek(medium, needle, &index, SeekFlag_MatchFindLast)) {
|
||||||
|
result = MakeCaret(index, index + needle.len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Caret FindNext(Buffer *buffer, String16 needle, Caret caret) {
|
||||||
|
Int pos = GetFront(caret);
|
||||||
String16 medium = GetString(*buffer, {pos, INT64_MAX});
|
String16 medium = GetString(*buffer, {pos, INT64_MAX});
|
||||||
|
|
||||||
Caret result = {};
|
Caret result = caret;
|
||||||
Int index = 0;
|
Int index = 0;
|
||||||
if (Seek(medium, needle, &index)) {
|
if (Seek(medium, needle, &index)) {
|
||||||
result = MakeCaret(pos + index + needle.len, pos + index);
|
result = MakeCaret(pos + index + needle.len, pos + index);
|
||||||
@@ -540,27 +558,6 @@ Caret FindInBuffer(Buffer *buffer, String16 needle, Caret caret, bool find_next
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (find_next && AreEqual(result, caret)) {
|
|
||||||
caret.range.min = Clamp(*buffer, caret.range.min + 1);
|
|
||||||
caret.range.max = Clamp(*buffer, caret.range.max + 1);
|
|
||||||
result = FindInBuffer(buffer, needle, caret, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Array<Range> FindAllInBuffer(Allocator allocator, Buffer *buffer, String16 needle) {
|
|
||||||
Array<Range> result = {allocator};
|
|
||||||
String16 string_buffer = GetString(*buffer);
|
|
||||||
for (Int pos = 0;;) {
|
|
||||||
Int index = 0;
|
|
||||||
String16 medium = Skip(string_buffer, pos);
|
|
||||||
if (!Seek(medium, needle, &index)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Add(&result, Rng(pos + index, pos + index + needle.len));
|
|
||||||
pos += needle.len;
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -580,9 +577,11 @@ void Command_IdentedNewLine(View *view) {
|
|||||||
EndEdit(buffer, &edits, &view->carets);
|
EndEdit(buffer, &edits, &view->carets);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Command_FindNext(View *seek_view, String16 needle) {
|
void Command_Find(View *seek_view, String16 needle, bool forward = true) {
|
||||||
Buffer *seek_buffer = GetBuffer(seek_view->active_buffer);
|
Buffer *seek_buffer = GetBuffer(seek_view->active_buffer);
|
||||||
Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true);
|
Caret caret = seek_view->carets[0];
|
||||||
|
if (forward) caret = FindNext(seek_buffer, needle, caret);
|
||||||
|
if (!forward) caret = FindPrev(seek_buffer, needle, caret);
|
||||||
seek_view->carets.len = 1;
|
seek_view->carets.len = 1;
|
||||||
seek_view->carets[0] = caret;
|
seek_view->carets[0] = caret;
|
||||||
}
|
}
|
||||||
@@ -756,21 +755,21 @@ void WindowCommand(Event event, Window *window, View *view) {
|
|||||||
|
|
||||||
if (Ctrl(SDLK_D)) {
|
if (Ctrl(SDLK_D)) {
|
||||||
String16 string = GetString(*buffer, view->carets[0].range);
|
String16 string = GetString(*buffer, view->carets[0].range);
|
||||||
Caret caret = FindInBuffer(buffer, string, view->carets[0], true);
|
Caret caret = FindNext(buffer, string, view->carets[0]);
|
||||||
Insert(&view->carets, caret, 0);
|
Insert(&view->carets, caret, 0);
|
||||||
MergeCarets(view);
|
MergeCarets(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ctrl(SDLK_F3)) {
|
if (Ctrl(SDLK_F3)) {
|
||||||
Buffer *search_buffer = GetBuffer(SearchBufferID);
|
Scratch scratch;
|
||||||
String16 search_string = GetString(*search_buffer);
|
String16 search_string = ToString16(scratch, window->search_string);
|
||||||
Caret caret = FindInBuffer(buffer, search_string, view->carets[0], true);
|
Caret caret = FindNext(buffer, search_string, view->carets[0]);
|
||||||
Insert(&view->carets, caret, 0);
|
Insert(&view->carets, caret, 0);
|
||||||
MergeCarets(view);
|
MergeCarets(view);
|
||||||
} else if (Press(SDLK_F3)) {
|
} else if (Press(SDLK_F3)) {
|
||||||
Buffer *search_buffer = GetBuffer(SearchBufferID);
|
Scratch scratch;
|
||||||
String16 search_string = GetString(*search_buffer);
|
String16 search_string = ToString16(scratch, window->search_string);
|
||||||
Caret caret = FindInBuffer(buffer, search_string, view->carets[0], true);
|
Caret caret = FindNext(buffer, search_string, view->carets[0]);
|
||||||
view->carets.len = 1;
|
view->carets.len = 1;
|
||||||
view->carets[0] = caret;
|
view->carets[0] = caret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,10 +207,19 @@ int LuaSearch(lua_State *L) {
|
|||||||
Window *seek_window = GetCurrentWindow();
|
Window *seek_window = GetCurrentWindow();
|
||||||
seek_window->search_string = lua_tostring(L, 1);
|
seek_window->search_string = lua_tostring(L, 1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
View *seek_view = GetView(seek_window->active_view);
|
View *seek_view = GetView(seek_window->active_view);
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Command_FindNext(seek_view, ToString16(scratch, seek_window->search_string));
|
Command_Find(seek_view, ToString16(scratch, seek_window->search_string), true);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaSearchB(lua_State *L) {
|
||||||
|
Window *seek_window = GetCurrentWindow();
|
||||||
|
seek_window->search_string = lua_tostring(L, 1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
View *seek_view = GetView(seek_window->active_view);
|
||||||
|
Scratch scratch;
|
||||||
|
Command_Find(seek_view, ToString16(scratch, seek_window->search_string), false);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,6 +246,7 @@ luaL_Reg LuaFunctions[] = {
|
|||||||
{ "AppendC", LuaAppendCmd},
|
{ "AppendC", LuaAppendCmd},
|
||||||
{ "OpenFilesHere", LuaOpenFilesHere},
|
{ "OpenFilesHere", LuaOpenFilesHere},
|
||||||
{ "Search", LuaSearch},
|
{ "Search", LuaSearch},
|
||||||
|
{ "SearchB", LuaSearchB},
|
||||||
{ NULL, NULL},
|
{ NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ WindowID ConsoleWindowID;
|
|||||||
|
|
||||||
ViewID ConsoleViewID;
|
ViewID ConsoleViewID;
|
||||||
BufferID DebugBufferID;
|
BufferID DebugBufferID;
|
||||||
BufferID SearchBufferID;
|
|
||||||
|
|
||||||
// @note:
|
// @note:
|
||||||
// Remember that WindowCommand works on window handed it down from HandleEvent
|
// Remember that WindowCommand works on window handed it down from HandleEvent
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ struct Window {
|
|||||||
Array<GotoCrumb> goto_history;
|
Array<GotoCrumb> goto_history;
|
||||||
Array<GotoCrumb> goto_redo;
|
Array<GotoCrumb> goto_redo;
|
||||||
|
|
||||||
|
// @todo: consider making this String16
|
||||||
String search_string;
|
String search_string;
|
||||||
|
|
||||||
double mouse_scroller_offset;
|
double mouse_scroller_offset;
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ void ReplaceTitleBarData(Window *window) {
|
|||||||
if (buffer->change_id != window->title_bar_last_buffer_change_id) {
|
if (buffer->change_id != window->title_bar_last_buffer_change_id) {
|
||||||
ApplyTitleBarChangesToWindow(window, view, buffer);
|
ApplyTitleBarChangesToWindow(window, view, buffer);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Window *last_window = GetWindow(window->title_bar_window);
|
Window *last_window = GetWindow(window->title_bar_window);
|
||||||
@@ -125,8 +124,6 @@ void ReplaceTitleBarData(Window *window) {
|
|||||||
AdjustCarets(edits, &caret_copy);
|
AdjustCarets(edits, &caret_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// String search_string = last_window->search_string;
|
|
||||||
// if (search_string.len) search_string = Format(scratch, " /%.*s", FmtString(search_string));
|
|
||||||
String s = Format(scratch, "%.*s:%lld:%lld", FmtString(last_buffer->name), (long long)xy.line + 1ll, (long long)xy.col + 1ll);
|
String s = Format(scratch, "%.*s:%lld:%lld", FmtString(last_buffer->name), (long long)xy.line + 1ll, (long long)xy.col + 1ll);
|
||||||
String16 string = ToString16(scratch, s);
|
String16 string = ToString16(scratch, s);
|
||||||
String16 string_to_replace = GetString(*buffer, replace_range);
|
String16 string_to_replace = GetString(*buffer, replace_range);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
- Remove pointers and use ViewIDs (enable array debug while doing this)
|
- Remove pointers and use ViewIDs (enable array debug while doing this)
|
||||||
|
|
||||||
- search as a command to execute which is going to be in the title bar
|
- ctrl + f - should find Search and select content or add Search
|
||||||
- search backwards
|
- search backwards
|
||||||
- some split selection commands
|
- some split selection commands
|
||||||
- assign commands or lua functions to F1-F8 keys
|
- assign commands or lua functions to F1-F8 keys
|
||||||
|
|||||||
Reference in New Issue
Block a user