Remove exec word, insert titlebar command, error reporting in titlebar, some lua commands

This commit is contained in:
Krzosa Karol
2024-09-28 07:40:00 +02:00
parent 9ea1e254e0
commit 35cc5ae48d
9 changed files with 11 additions and 112 deletions

View File

@@ -498,23 +498,6 @@ Range EncloseScope(Buffer *buffer, Int pos, wchar_t open, wchar_t close) {
}
return result;
}
Range EncloseExecWord(Buffer *buffer, Int pos) {
for (Int i = pos; i >= 0 && i >= pos - 1024; i -= 1) {
if (GetChar(buffer, i) == L'#') {
pos = i + 1;
break;
}
}
Range result = {GetWordStart(buffer, pos), GetWordEnd(buffer, pos)};
Int seek = SkipSpaces(buffer, result.max);
Int scope_end = FindScopeEnd(buffer, seek, 1024, L'(', L')');
if (seek == scope_end) scope_end = FindScopeEnd(buffer, seek, 1024, L'{', L'}');
if (seek == scope_end) scope_end = FindScopeEnd(buffer, seek, 1024, L'\'', L'\'');
if (seek == scope_end) scope_end = FindScopeEnd(buffer, seek, 1024, L'\"', L'\"');
if (seek != scope_end) result.max = scope_end + 1;
return result;
}
Range EncloseLine(Buffer *buffer, Int pos) {
Range result = {GetLineStart(buffer, pos), GetLineEnd(buffer, pos)};

View File

@@ -1,12 +1,12 @@
void LoadBigText(Buffer *buffer, int size = 5000000) {
for (int i = 0; i < size; i += 1) {
IKnowWhatImDoing_ReplaceText(buffer, GetEndAsRange(buffer), L"Line number and another meme or something of the sort which is here or there frankly somewhere\n");
IKnowWhatImDoing_ReplaceText(buffer, GetEndAsRange(buffer), L"Line number or something of the sort which is here or there or maybe somewhere else\n");
}
}
void LoadBigLine(Buffer *buffer, int size = 5000000) {
for (int i = 0; i < size; i += 1) {
IKnowWhatImDoing_ReplaceText(buffer, GetEndAsRange(buffer), L"Line number and another meme or something of the sort which is here or there frankly somewhere");
IKnowWhatImDoing_ReplaceText(buffer, GetEndAsRange(buffer), L"Line number or something of the sort which is here or there or maybe somewhere else | ");
}
}

View File

@@ -84,7 +84,7 @@ void MouseExecWord(Event event) {
if (mouse_in_document) {
Int p = ScreenSpaceToBufferPosErrorOutOfBounds(active.window, active.view, active.buffer, mouse);
if (p != -1) {
Range enclose = EncloseExecWord(active.buffer, p);
Range enclose = EncloseLoadWord(active.buffer, p);
if (InBounds(active.view->carets[0].range, p)) {
enclose = active.view->carets[0].range;
}
@@ -209,10 +209,6 @@ void ReportWarningf(const char *fmt, ...) {
STRING_FORMAT(scratch, fmt, string);
View *null_view = GetView(NullViewID);
Command_Append(null_view, string, true);
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) {
@@ -888,42 +884,3 @@ void Command_FuzzySort(View *view, String16 needle) {
Command_Replace(view, GetString(temp_buffer));
Command_SelectRangeOneCursor(view, Rng(0));
}
void Command_InsertTitlebarCommand(BSet title, String16 needle, String16 initial_value, bool select_entire_thing) {
Scratch scratch;
String16 quoted16 = {};
{
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);
}
Range needle_range = {};
int64_t index = 0;
String16 buffer_string = GetString(title.buffer);
if (Seek(buffer_string, needle, &index)) {
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);
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

@@ -437,7 +437,7 @@ void OnCommand(Event event) {
}
if (CtrlPress(SDLK_F)) {
Command_SelectTitlebarCommand(active.window, L"#Search('");
// @todo: Search in current buffer
}
if (CtrlPress(SDLK_S)) {
@@ -456,7 +456,7 @@ void OnCommand(Event event) {
if (CtrlShiftPress(SDLK_G)) {
} else if (CtrlPress(SDLK_G)) {
Command_SelectTitlebarCommand(active.window, L"#FuzzySort('");
}
if (CtrlShiftPress(SDLK_W)) {
@@ -469,7 +469,7 @@ void OnCommand(Event event) {
if (should_enclose || CtrlShiftPress(SDLK_Q)) {
Caret caret = active.view->carets[0];
Range range = caret.range;
if (GetSize(caret.range) == 0) range = EncloseExecWord(active.buffer, GetFront(caret));
if (GetSize(caret.range) == 0) range = EncloseLoadWord(active.buffer, GetFront(caret));
String16 string = GetString(active.buffer, range);
Command_EvalLua(active.view, string);

View File

@@ -78,17 +78,6 @@ void Open(String16 path) {
Open(string);
}
int Lua_FuzzySort(lua_State *L) {
String string = lua_tostring(L, 1);
lua_pop(L, 1);
Scratch scratch;
String16 string16 = ToString16(scratch, string);
BSet main = GetActiveMainSet();
Command_FuzzySort(main.view, string16);
return 0;
}
int Lua_AppendCmd(lua_State *L) {
String string = lua_tostring(L, 1);
lua_pop(L, 1);
@@ -148,12 +137,6 @@ int Lua_Kill(lua_State *L) {
return 0;
}
int Lua_Error(lua_State *L) {
Buffer *buffer = GetBuffer(NullBufferID);
Open(buffer->name);
return 0;
}
int Lua_GetLoadWord(lua_State *L) {
BSet active = GetActiveSet();
Range range = active.view->carets[0].range;
@@ -286,25 +269,6 @@ int Lua_Ls(lua_State *L) {
return 0;
}
int Lua_Search(lua_State *L) {
BSet main = GetActiveMainSet();
main.window->search_string = lua_tostring(L, 1);
lua_pop(L, 1);
Scratch scratch;
Command_Find(main.view, ToString16(scratch, main.window->search_string), true);
return 0;
}
int Lua_SearchB(lua_State *L) {
BSet main = GetActiveMainSet();
main.window->search_string = lua_tostring(L, 1);
lua_pop(L, 1);
Scratch scratch;
Command_Find(main.view, ToString16(scratch, main.window->search_string), false);
return 0;
}
int Lua_Rename(lua_State *L) {
String string = lua_tostring(L, 1);
lua_pop(L, 1);
@@ -557,7 +521,6 @@ bool EvalString(Allocator allocator, String16 string16) {
}
bool Command_EvalLua(View *view, String16 string) {
if (string.len && string.data[0] == L'#') string = Skip(string, 1);
Scratch scratch;
Buffer *buffer = GetBuffer(view->active_buffer);
return EvalString(scratch, string);

View File

@@ -1,10 +1,8 @@
luaL_Reg LuaFunctions[] = {
{"FuzzySort", Lua_FuzzySort},
{"AppendCmd", Lua_AppendCmd},
{"C", Lua_C},
{"Cmd", Lua_Cmd},
{"Kill", Lua_Kill},
{"Error", Lua_Error},
{"GetLoadWord", Lua_GetLoadWord},
{"New", Lua_New},
{"Open", Lua_Open},
@@ -19,8 +17,6 @@ luaL_Reg LuaFunctions[] = {
{"GetActiveMainWindowBufferName", Lua_GetActiveMainWindowBufferName},
{"GetActiveMainWindowBufferDir", Lua_GetActiveMainWindowBufferDir},
{"Ls", Lua_Ls},
{"Search", Lua_Search},
{"SearchB", Lua_SearchB},
{"Rename", Lua_Rename},
{"Play", Lua_Play},
{NULL, NULL},

View File

@@ -262,7 +262,7 @@ int main(int argc, char **argv)
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
SDLWindow = SDL_CreateWindow("Text editor", 1280, 720, window_flags);
SDLWindow = SDL_CreateWindow("Text editor", 1920, 1080, window_flags);
if (SDLWindow == NULL) {
ReportErrorf("Couldn't create window! %s", SDL_GetError());
return 1;

View File

@@ -1,3 +1,5 @@
- report errors (try showing a window)
- adding items to directory should create files on save - it should ask the user (syntax: dir/ | file)
- ask user if he really wants to quit even though he has an unsaved buffer - popup window
- test the code editor: try writing in it, try browsing in it, create test tooling

View File

@@ -187,8 +187,6 @@ void DrawWindow(Window *window, Event &event) {
// Underline word under mouse cursor
if (Ctrl()) {
auto enclose_proc = Shift() ? EncloseExecWord : EncloseLoadWord;
Caret caret = view->carets[0];
Vec2I mouse = MouseVec2I();
bool mouse_in_document = CheckCollisionPointRec(mouse, window->document_rect);
@@ -197,7 +195,7 @@ void DrawWindow(Window *window, Event &event) {
Buffer *buffer = GetBuffer(view->active_buffer);
Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse);
if (p != -1) {
Range range = enclose_proc(buffer, p);
Range range = EncloseLoadWord(buffer, p);
if (InBounds(caret.range, p)) range = caret.range;
DrawUnderline(window, view, buffer, range, ColorMouseUnderline, 2);
}
@@ -205,7 +203,7 @@ void DrawWindow(Window *window, Event &event) {
if (is_active) {
if (GetSize(caret.range) == 0) {
Range range = enclose_proc(buffer, caret.range.min);
Range range = EncloseLoadWord(buffer, caret.range.min);
DrawUnderline(window, view, buffer, range, ColorCaretUnderline);
} else {
DrawUnderline(window, view, buffer, caret.range, ColorCaretUnderline);