From 9215205aba906860109550192a5b371c1566d0cc Mon Sep 17 00:00:00 2001 From: Krzosa Karol Date: Mon, 5 Aug 2024 07:12:28 +0200 Subject: [PATCH] Load lua functions from an array --- .gitignore | 2 +- src/text_editor/commands.cpp | 8 +++-- src/text_editor/commands_window.cpp | 2 +- src/text_editor/lua_api.cpp | 50 ++++++++++++++--------------- src/text_editor/todo.txt | 47 +++++++++++++-------------- 5 files changed, 55 insertions(+), 54 deletions(-) diff --git a/.gitignore b/.gitignore index 785fdc0..37fadcb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ x64/Debug x64/Release .vs/ -src/external +src/external/SDL build/ *.rdbg \ No newline at end of file diff --git a/src/text_editor/commands.cpp b/src/text_editor/commands.cpp index 846b74c..9c5f4c3 100644 --- a/src/text_editor/commands.cpp +++ b/src/text_editor/commands.cpp @@ -262,13 +262,15 @@ bool GlobalCommand(Event event) { } } + if (event.ctrl && Mouse(RIGHT)) { + GoBackToLastCrumb(); + } + // @todo: maybe move some of this stuff to window command ??? // for now let's leave it because we are relaying on global state // - maybe just do the check if active window is matching the DocumentSelected window // - if scrollbar selected then don't invoke window command - if (event.alt && Mouse(LEFT)) { - GoBackToLastCrumb(); - } else if (event.ctrl && Mouse(LEFT)) { + if (event.ctrl && Mouse(LEFT)) { Vec2I mouse = MouseVec2I(); Window *window = GetActiveWindow(); diff --git a/src/text_editor/commands_window.cpp b/src/text_editor/commands_window.cpp index bb1d3c5..47928f9 100644 --- a/src/text_editor/commands_window.cpp +++ b/src/text_editor/commands_window.cpp @@ -818,7 +818,7 @@ void WindowCommand(Event event, Window *window, View *view) { Open(string); } - if (Alt(SDLK_Q)) { + if (Ctrl(SDLK_W)) { GoBackToLastCrumb(); } diff --git a/src/text_editor/lua_api.cpp b/src/text_editor/lua_api.cpp index 0b7d348..721ac40 100644 --- a/src/text_editor/lua_api.cpp +++ b/src/text_editor/lua_api.cpp @@ -4,9 +4,9 @@ String16 LuaCommandResult = {}; String ListFiles(String path) { Scratch scratch; Array strings = {scratch}; - Add(&strings, String{"open \"..\""}); + Add(&strings, String{"Open \"..\""}); for (FileIter iter = IterateFiles(scratch, path); IsValid(iter); Advance(&iter)) { - String string = Format(scratch, "open \"%.*s\"", FmtString(iter.absolute_path)); + String string = Format(scratch, "Open \"%.*s\"", FmtString(iter.absolute_path)); Add(&strings, string); } Add(&strings, Format(scratch, "working dir = %.*s", FmtString(WorkingDir))); @@ -76,6 +76,14 @@ int LuaOpen(lua_State *L) { return 0; } +int LuaPrint(lua_State *L) { + Scratch scratch; + String string = luaL_checkstring(L, 1); + lua_pop(L, 1); + AppendToConsole(string); + return 0; +} + int LuaListOpenBuffers(lua_State *L) { Scratch scratch; Array strings = {scratch}; @@ -139,33 +147,25 @@ int LuaGetCurrentBufferDir(lua_State *L) { return 1; } +luaL_Reg LuaFunctions[] = { + { "Open", LuaOpen}, + { "list_buffers", LuaListOpenBuffers}, + { "ListBuffers", LuaListOpenBuffersObject}, + { "GetWorkingDir", LuaGetWorkingDir}, + { "FileExists", LuaFileExists}, + {"GetCurrentBufferName", LuaGetCurrentBufferName}, + { "GetCurrentBufferDir", LuaGetCurrentBufferDir}, + { NULL, NULL}, +}; + void InitLua() { LuaState = luaL_newstate(); luaL_openlibs(LuaState); - lua_pushcfunction(LuaState, LuaOpen); - lua_setglobal(LuaState, "open"); - - lua_pushcfunction(LuaState, LuaListOpenBuffers); - lua_setglobal(LuaState, "list_buffers"); - - lua_pushcfunction(LuaState, LuaListOpenBuffersObject); - lua_setglobal(LuaState, "ListBuffers"); - - lua_pushcfunction(LuaState, LuaOpenBigBuffer); - lua_setglobal(LuaState, "open_big_buffer"); - - lua_pushcfunction(LuaState, LuaGetWorkingDir); - lua_setglobal(LuaState, "GetWorkingDir"); - - lua_pushcfunction(LuaState, LuaFileExists); - lua_setglobal(LuaState, "FileExists"); - - lua_pushcfunction(LuaState, LuaGetCurrentBufferName); - lua_setglobal(LuaState, "GetCurrentBufferName"); - - lua_pushcfunction(LuaState, LuaGetCurrentBufferDir); - lua_setglobal(LuaState, "GetCurrentBufferDir"); + for (int i = 0; LuaFunctions[i].name; i += 1) { + lua_pushcfunction(LuaState, LuaFunctions[i].func); + lua_setglobal(LuaState, LuaFunctions[i].name); + } } String16 EvalString(Allocator allocator, String16 string16) { diff --git a/src/text_editor/todo.txt b/src/text_editor/todo.txt index 1809c5f..95ded8d 100644 --- a/src/text_editor/todo.txt +++ b/src/text_editor/todo.txt @@ -1,7 +1,7 @@ - page up and down should also scroll and leave you in exactly same scroll - I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection) +- ctrl + delete maybe should stop on new line but it keeps on going -- bug treats numbers as whitespace or whatever - bug: Latin-1 is matched as column for some reason in ApplyRules!! - mouse execute (control right click) - alt right click what to do ? (toggle console?) @@ -9,45 +9,44 @@ - should be able click on title bar of windows which disappear on losing focus - console window should close on esacpe but make it more coherent - Ctrl + G should select the line number in bar - +- consider highlighting different things on alt +- search as a command to execute which is going to be in the title bar +- each buffer needs a directory even the special ones: C:\a\b\c\+errors? - open directories - resulting in buffer with dir listing and proper buffer name +- clean \r\n into \n on trim and load + - baked font as fallback - expose font and font size to config - global config and local config + - load all files in a directory -- Search all buffers in 10X style, incrementally searched results popping up on every key press (maybe we need coroutine library in C so this is easier?) -- select space between parens,braces but make it good -- switch to previous view (ctrl + tab) -- we could rewrite kill lines with simpler commands - extend selection to encompass lines->replace - search backwards -- search as a command to execute which is going to be in the title bar +- Search all buffers in 10X style, incrementally searched results popping up on every key press (maybe we need coroutine library in C so this is easier?) +- Search and replace + +- select space between parens,braces but make it good - make the editor replayable, store events and then replay, be careful about globals -- I want a way to assign flags to buffers/views/windows from user perspective so that console window concept can be created from user space - Implement shell interaction (here we also could use the coroutine library) - word complete -- Colored strings -- Set scroll centered -- font cache and on demand unicode loads -- Search and replace -- Search result buffer -- yeet sheet -- color parens, braces -- auto register commands, but we need to figure out how to properly structure lua stuff - -- double click - start enclosing word, triple click - start enclosing lines, merge 2 cursor selection - start treating it as anchor - Windows +- switch to previous view (ctrl + tab) +- shift + ctrl + click should open a new window and then with alt it probably should kill it - layout using a tree!! - I don't think we need WindowIDs - layouting, resize windows - try to incorporate the acme square which allows you to put windows wherever and also scale the border -- files - - load directory - - file lister - - commands should run in a directory specified by buffer so you don't have to specify whole path - - each buffer would need a directory even the special ones: C:\a\b\c\+errors - - this could be used for storing the path in the command window +backlog +- maybe open should return multiple options if there are many more? (like in sublime if many symbols you get a window and you choose and it automatically jumps you to the symbol in the background) +- we could rewrite kill lines with simpler commands - extend selection to encompass lines->replace +- I want a way to assign flags to buffers/views/windows from user perspective so that console window concept can be created from user space +- font cache and on demand unicode loads +- Set scroll centered, what was the use case for this? +- color parens, braces +- auto register commands, but we need to figure out how to properly structure lua stuff +- double click - start enclosing word, triple click - start enclosing lines, merge 2 cursor selection - start treating it as anchor +- Colored strings