Report errors idea using titlebar

This commit is contained in:
Krzosa Karol
2024-08-15 11:54:32 +02:00
parent 41a05fb08c
commit 7ed46b9724
8 changed files with 62 additions and 46 deletions

View File

@@ -1,25 +1,25 @@
Style.WaitForEvents = 0
-- Style.WaitForEvents = 0
AddCo(function()
Play{
{kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
{kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
{kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
{kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
{kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
{kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
{kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
{kind = 10, key = KEY_Q , xwindow = 1280, ywindow = 720, ctrl = 1},
{kind = 10, key = KEY_PAGE_DOWN, xmouse = 0, ymouse = 0, xwindow = 1280, ywindow = 720},
{kind = 111},
}
-- for i = 1,8 do coroutine.yield() end
while coroutine.yield().kind ~= 111 do end
-- AddCo(function()
-- Play{
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_DOWN, xwindow = 1280, ywindow = 720},
-- {kind = 10, key = KEY_Q , xwindow = 1280, ywindow = 720, ctrl = 1},
-- {kind = 10, key = KEY_PAGE_DOWN, xmouse = 0, ymouse = 0, xwindow = 1280, ywindow = 720},
-- {kind = 111},
-- }
-- -- for i = 1,8 do coroutine.yield() end
-- while coroutine.yield().kind ~= 111 do end
local buffer_name = GetActiveMainWindowBufferName()
Print("buffer name = "..buffer_name)
if buffer_name == "C:/Work/text_editor/src/text_editor/buffer_history.cpp" then
Play{{kind = 2}}
end
end)
-- local buffer_name = GetActiveMainWindowBufferName()
-- Print("buffer name = "..buffer_name)
-- if buffer_name == "C:/Work/text_editor/src/text_editor/buffer_history.cpp" then
-- Play{{kind = 2}}
-- end
-- end)

View File

@@ -210,12 +210,9 @@ void ReportWarningf(const char *fmt, ...) {
View *null_view = GetView(NullViewID);
Command_Append(null_view, string, true);
// @todo: proper warning
// Window *window = GetWindowWithView(null_view->id);
// if (!window) window = GetActiveMainSet().window;
// CheckpointBeforeGoto(window);
// window->active_view = null_view->id;
// ActiveWindow = window->id;
void Command_InsertTitlebarCommand(BSet title, String16 needle, String16 string, bool select_entire);
BSet title = GetActiveTitleSet();
Command_InsertTitlebarCommand(title, L"#Error(\"", ToString16(scratch, string), true);
}
void Command_MoveCursorsByPageSize(Window *window, int direction, bool shift = false) {
@@ -887,26 +884,41 @@ void Command_FuzzySort(View *view, String16 needle) {
Command_SelectRangeOneCursor(view, Rng(0));
}
void Command_SelectTitlebarCommand(Window *window, String16 needle) {
BSet title = GetTitleSet(window);
String16 buffer_string = GetString(title.buffer);
ActiveWindow = title.window->id;
title.window->auto_enclose = true;
void Command_InsertTitlebarCommand(BSet title, String16 needle, String16 initial_value, bool select_entire_thing) {
Scratch scratch;
String16 quoted16 = {};
{
String needle8 = ToString(scratch, needle);
String quoted = Format(scratch, "%.*s\")", FmtString(needle8));
quoted16 = ToString16(scratch, quoted);
String needle8 = ToString(scratch, needle);
String initial_value8 = ToString(scratch, initial_value);
String quoted = Format(scratch, "%.*s%.*s\")", FmtString(needle8), FmtString(initial_value8));
quoted16 = ToString16(scratch, quoted);
}
int64_t index = 0;
Range needle_range = {};
int64_t index = 0;
String16 buffer_string = GetString(title.buffer);
if (Seek(buffer_string, needle, &index)) {
Command_SelectRangeOneCursor(title.view, Rng(index + needle.len));
Range range = EncloseExecWord(title.buffer, index);
Command_SelectRangeOneCursor(title.view, Rng(range.min - 1, range.max));
Command_Replace(title.view, quoted16);
needle_range = {index + needle.len, index + needle.len + initial_value.len};
} else {
Command_SelectRangeOneCursor(title.view, GetEndAsRange(title.buffer));
Command_Replace(title.view, quoted16);
Command_SelectRangeOneCursor(title.view, GetEndAsRange(title.buffer) - 2);
Int end = GetEndAsRange(title.buffer).max - 2;
needle_range = {end - initial_value.len, end};
}
if (select_entire_thing) {
needle_range.min -= needle.len;
needle_range.max += 2;
}
Command_SelectRangeOneCursor(title.view, MakeCaret(needle_range.max, needle_range.min));
}
void Command_SelectTitlebarCommand(Window *window, String16 needle) {
BSet title = GetTitleSet(window);
ActiveWindow = title.window->id;
title.window->auto_enclose = true;
Command_InsertTitlebarCommand(title, needle, L"", false);
}

View File

@@ -449,6 +449,10 @@ void OnCommand(Event event) {
Open(name);
}
if (CtrlPress(SDLK_T)) {
ActiveWindow = GetWindow(active.window->title_bar_window)->id;
}
if (CtrlShiftPress(SDLK_G)) {
} else if (CtrlPress(SDLK_G)) {
Command_SelectTitlebarCommand(active.window, L"#FuzzySort(\"");

View File

@@ -469,7 +469,7 @@ bool EvalString(Allocator allocator, String16 string16) {
String string = ToString(scratch, string16);
if (luaL_dostring(LuaState, string.data) != LUA_OK) {
const char *error_message = lua_tostring(LuaState, -1);
ReportConsolef("Execution error! %s", error_message);
ReportWarningf("Execution error! %s", error_message);
lua_pop(LuaState, 1);
return false;
}

View File

@@ -225,7 +225,7 @@ BSet GetActiveMainSet() {
BSet GetActiveTitleSet() {
Window *window = GetWindow(ActiveWindow);
if (window->is_title_bar) window = GetWindow(window->title_bar_window);
if (!window->is_title_bar) window = GetWindow(window->title_bar_window);
return GetBSet(window);
}

View File

@@ -8,7 +8,6 @@ void Test(mco_coro *co) {
Add(&EventPlayback, {EVENT_KEY_PRESS, SDLK_DOWN, 1280, 720});
Add(&EventPlayback, {EVENT_KEY_PRESS, SDLK_Q, 1280, 720});
GetLast(EventPlayback)->ctrl = 1;
Add(&EventPlayback, {EVENT_KEY_PRESS, SDLK_PAGEDOWN, 1280, 720});
Add(&EventPlayback, {111});
for (Event *event = Yield(co); event->kind != 111; event = Yield(co)) {

View File

@@ -317,8 +317,9 @@ int main(int argc, char **argv)
InitLuaConfig();
StyleWaitForEvents = false;
AddCo(Test);
// :Tests
// StyleWaitForEvents = false;
// AddCo(Test);
Serializer ser = {EventBuffer};
while (AppIsRunning) {

View File

@@ -5,8 +5,8 @@
- Find matches using grep, change things in that buffer then apply those changes to all items
- group history entries so the you can rollback through multiple ones at once and not waste time on skipping whitespace trimming or deleting every character
- Fuzzy search buffer which uses titlebar as query!
- ReportWarning should be signaled visibly but you should be able to do things! no focus switching
- fix fucking conversions between strings!!!!!! we need to have stb_sprintf 16
- OnWindowCommand allow config user to overwrite the WindowCommand keybinding, introduce his own