diff --git a/src/basic/string16.cpp b/src/basic/string16.cpp index 8396eea..e24728d 100644 --- a/src/basic/string16.cpp +++ b/src/basic/string16.cpp @@ -262,3 +262,18 @@ Int ChopNumber(String16 *string) { Int result = strtoll(num_string.data, NULL, 10) - 1; return result; } + +String16 ChopWhitespace(String16 *string) { + String16 new_string = *string; + String16 whitespace = {string->data, 0}; + for (int64_t i = 0; i < string->len; i += 1) { + if (IsWhitespace(string->data[i])) { + new_string = Skip(new_string, 1); + whitespace.len += 1; + } else { + break; + } + } + *string = new_string; + return whitespace; +} diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index 89a7136..26908cd 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -580,6 +580,13 @@ void Command_IdentedNewLine(View *view) { EndEdit(buffer, &edits, &view->carets); } +void Command_FindNext(View *seek_view, String16 needle) { + Buffer *seek_buffer = GetBuffer(seek_view->active_buffer); + Caret caret = FindInBuffer(seek_buffer, needle, seek_view->carets[0], true); + seek_view->carets.len = 1; + seek_view->carets[0] = caret; +} + void WindowCommand(Event event, Window *window, View *view) { ProfileFunction(); Buffer *buffer = GetBuffer(view->active_buffer); diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index 0e86cd5..f771f8d 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -193,10 +193,6 @@ int LuaGetCurrentBufferDir(lua_State *L) { return 1; } -void OpenFilesHereRecursive(Window *window, String path) { - Scratch scratch; -} - int LuaOpenFilesHere(lua_State *L) { Window *window = GetWindow(GetLastActiveWindow()); @@ -204,7 +200,17 @@ int LuaOpenFilesHere(lua_State *L) { for (FileIter it = IterateFiles(scratch, GetCurrentBufferDir()); IsValid(it); Advance(&it)) { WindowOpenBufferView(window, it.absolute_path); } + return 0; +} +int LuaSearch(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_FindNext(seek_view, ToString16(scratch, seek_window->search_string)); return 0; } @@ -230,6 +236,7 @@ luaL_Reg LuaFunctions[] = { { "NewC", LuaNewCmd}, { "AppendC", LuaAppendCmd}, { "OpenFilesHere", LuaOpenFilesHere}, + { "Search", LuaSearch}, { NULL, NULL}, }; diff --git a/src/text_editor/text_editor.h b/src/text_editor/text_editor.h index 11cb854..6390c0a 100644 --- a/src/text_editor/text_editor.h +++ b/src/text_editor/text_editor.h @@ -77,6 +77,8 @@ struct Window { Array goto_history; Array goto_redo; + String search_string; + double mouse_scroller_offset; int z; diff --git a/src/text_editor/title_bar.cpp b/src/text_editor/title_bar.cpp index 25f73b1..eb9109f 100644 --- a/src/text_editor/title_bar.cpp +++ b/src/text_editor/title_bar.cpp @@ -125,6 +125,8 @@ void ReplaceTitleBarData(Window *window) { 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); String16 string = ToString16(scratch, s); String16 string_to_replace = GetString(*buffer, replace_range);