Rename to Config, Fix slowness of ShowCommands and improve quality

This commit is contained in:
krzosa
2025-12-21 22:26:15 +01:00
parent 79d709d391
commit 725cdde007
10 changed files with 46 additions and 33 deletions

View File

@@ -1,7 +1,6 @@
- What precise workflow do I need for me to be viable to use this? - What precise workflow do I need for me to be viable to use this?
- From a user (novice) point of view, how does it look like? - From a user (novice) point of view, how does it look like?
- Remove LUA and replace with keybindings, config, commands
- "DO YOU REALLY WANT TO QUIT?" popup - "DO YOU REALLY WANT TO QUIT?" popup
- open all in the folder and ctrl + p like in VSCode (without special buffers) - open all in the folder and ctrl + p like in VSCode (without special buffers)
- Guide on the first page for new users with links to configs, tutorials - Guide on the first page for new users with links to configs, tutorials

View File

@@ -150,7 +150,7 @@ void Test(mco_coro *co) {
} }
void InitTests() { void InitTests() {
StyleWaitForEvents = false; ConfigWaitForEvents = false;
TestDir = Format(TestArena, "%S/test_env", GetExeDir(TestArena)); TestDir = Format(TestArena, "%S/test_env", GetExeDir(TestArena));
CoAdd(Test); CoAdd(Test);
} }

View File

@@ -1005,7 +1005,7 @@ API void UndoEdit(Buffer *buffer, Array<Caret> *carets) {
if (buffer->undo_stack.len > 0) { if (buffer->undo_stack.len > 0) {
HistoryEntry *next = GetLast(buffer->undo_stack); HistoryEntry *next = GetLast(buffer->undo_stack);
if (entry.time - next->time <= StyleUndoMergeTimeout) { if (entry.time - next->time <= ConfigUndoMergeTimeout) {
UndoEdit(buffer, carets); UndoEdit(buffer, carets);
} }
} }

View File

@@ -718,14 +718,14 @@ void Command_Undo() {
} RegisterCommand(Command_Undo, "ctrl-z"); } RegisterCommand(Command_Undo, "ctrl-z");
void Command_MakeFontLarger() { void Command_MakeFontLarger() {
StyleFontSize += 1; ConfigFontSize += 1;
ReloadFont(StyleFont, (U32)StyleFontSize); ReloadFont(ConfigFont, (U32)ConfigFontSize);
} RegisterCommand(Command_MakeFontLarger, "ctrl-equals"); } RegisterCommand(Command_MakeFontLarger, "ctrl-equals");
void Command_MakeFontSmaller() { void Command_MakeFontSmaller() {
if (StyleFontSize > 4) { if (ConfigFontSize > 4) {
StyleFontSize -= 1; ConfigFontSize -= 1;
ReloadFont(StyleFont, (U32)StyleFontSize); ReloadFont(ConfigFont, (U32)ConfigFontSize);
} }
} RegisterCommand(Command_MakeFontSmaller, "ctrl-minus"); } RegisterCommand(Command_MakeFontSmaller, "ctrl-minus");

View File

@@ -56,7 +56,7 @@ String AsString(Lexer *lex) {
} }
void EatWhitespace(Lexer *lex) { void EatWhitespace(Lexer *lex) {
while (IsWhitespace(At(lex))) { while (At(lex) != '\n' && IsWhitespace(At(lex))) {
Advance(lex); Advance(lex);
} }
} }

View File

@@ -74,6 +74,7 @@ String Intern(InternTable *table, String string) {
// optimize worst offenders (like event text) // optimize worst offenders (like event text)
InternTable GlobalInternTable; InternTable GlobalInternTable;
Function *LastExecutedCommand;
Array<CommandData> CommandFunctions; Array<CommandData> CommandFunctions;
Array<FunctionData> TestFunctions; Array<FunctionData> TestFunctions;
Array<Variable> Variables; Array<Variable> Variables;
@@ -143,13 +144,13 @@ RegisterVariable(Color, ColorTitleBarActiveBackground, {0xfe, 0xfe, 0xfe, 0xfe})
RegisterVariable(Color, ColorTitleBarSelection, GruvboxLight3); RegisterVariable(Color, ColorTitleBarSelection, GruvboxLight3);
RegisterVariable(Color, ColorResizerBackground, GruvboxLight0Hard); RegisterVariable(Color, ColorResizerBackground, GruvboxLight0Hard);
RegisterVariable(Color, ColorResizerOutline, GruvboxLight3); RegisterVariable(Color, ColorResizerOutline, GruvboxLight3);
RegisterVariable(Int, StyleWaitForEvents, 1); RegisterVariable(Int, ConfigWaitForEvents, 1);
RegisterVariable(Int, StyleDrawLineNumbers, 1); RegisterVariable(Int, ConfigDrawLineNumbers, 1);
RegisterVariable(Int, StyleDrawScrollbar, 1); RegisterVariable(Int, ConfigDrawScrollbar, 1);
RegisterVariable(Int, StyleIndentSize, 4); RegisterVariable(Int, ConfigIndentSize, 4);
RegisterVariable(Int, StyleFontSize, 15); RegisterVariable(Int, ConfigFontSize, 15);
RegisterVariable(Int, StyleFontFilter, 0); RegisterVariable(Int, ConfigFontFilter, 0);
RegisterVariable(String, StyleFont, "/home/krz/text_editor/package/CascadiaMono.ttf"); RegisterVariable(String, ConfigFont, "/home/krz/text_editor/package/CascadiaMono.ttf");
RegisterVariable(String, StyleVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat"); RegisterVariable(String, ConfigVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
RegisterVariable(Float, StyleUndoMergeTimeout, 0.3); RegisterVariable(Float, ConfigUndoMergeTimeout, 0.3);
RegisterVariable(String, ConfigInternetBrowser, "firefox"); RegisterVariable(String, ConfigInternetBrowser, "firefox");

View File

@@ -33,7 +33,7 @@
#include "process.cpp" #include "process.cpp"
#include "event.cpp" #include "event.cpp"
#include "parser.cpp" #include "config.cpp"
#include "commands.cpp" #include "commands.cpp"
#include "commands_clipboard.cpp" #include "commands_clipboard.cpp"
@@ -392,7 +392,10 @@ void OnCommand(Event event) {
For (CommandFunctions) { For (CommandFunctions) {
if (it.trigger && MatchEvent(it.trigger, &event)) { if (it.trigger && MatchEvent(it.trigger, &event)) {
double start = GetTimeSeconds();
it.function(); it.function();
ReportConsolef("%S: %f", it.name, GetTimeSeconds() - start);
LastExecutedCommand = it.function;
} }
} }
@@ -520,7 +523,7 @@ void Windows_SetupVCVarsall(mco_coro *co) {
Scratch scratch; Scratch scratch;
String working_dir = WorkDir; String working_dir = WorkDir;
String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-"); String buffer_name = GetUniqueBufferName(working_dir, "vcvarsall-");
String cmd = Format(scratch, "\"%S\" && set", StyleVCVarsall); String cmd = Format(scratch, "\"%S\" && set", ConfigVCVarsall);
view = ExecHidden(buffer_name, cmd, working_dir); view = ExecHidden(buffer_name, cmd, working_dir);
} }
for (;;) { for (;;) {
@@ -568,7 +571,7 @@ void MainLoop() {
Update(it); Update(it);
} }
WaitForEvents = StyleWaitForEvents; WaitForEvents = ConfigWaitForEvents;
if (IsDocumentSelectionValid() || IsScrollbarSelectionValid() || ActiveProcesses.len) { if (IsDocumentSelectionValid() || IsScrollbarSelectionValid() || ActiveProcesses.len) {
WaitForEvents = false; WaitForEvents = false;
} }
@@ -710,7 +713,7 @@ int main(int argc, char **argv)
InitBuffers(); InitBuffers();
InitRender(); InitRender();
ReloadFont(StyleFont, (U32)StyleFontSize); ReloadFont(ConfigFont, (U32)ConfigFontSize);
InitWindows(); InitWindows();
InitOS(ReportWarningf); InitOS(ReportWarningf);

View File

@@ -403,9 +403,9 @@ void Delete(View *view, int direction, bool ctrl = false) {
Range indent_range = GetIndentRangeAtPos(buffer, it.range.min); Range indent_range = GetIndentRangeAtPos(buffer, it.range.min);
if (ctrl == false && it.range.min > indent_range.min && it.range.max <= indent_range.max) { if (ctrl == false && it.range.min > indent_range.min && it.range.max <= indent_range.max) {
Int offset = it.range.min - indent_range.min; Int offset = it.range.min - indent_range.min;
Int to_delete = (offset % (StyleIndentSize)); Int to_delete = (offset % (ConfigIndentSize));
if (to_delete == 0) to_delete = StyleIndentSize; if (to_delete == 0) to_delete = ConfigIndentSize;
to_delete = Clamp(to_delete, (Int)1, StyleIndentSize); to_delete = Clamp(to_delete, (Int)1, ConfigIndentSize);
for (Int i = 0; i < to_delete; i += 1) { for (Int i = 0; i < to_delete; i += 1) {
it = MoveCaret(buffer, it, direction, false, SHIFT_PRESS); it = MoveCaret(buffer, it, direction, false, SHIFT_PRESS);
} }
@@ -472,12 +472,12 @@ void IndentSelectedLines(View *view, bool shift = false) {
Range pos_range_of_line = GetLineRange(buffer, i); Range pos_range_of_line = GetLineRange(buffer, i);
if (!shift) { if (!shift) {
String16 whitespace_string = {u" ", StyleIndentSize}; String16 whitespace_string = {u" ", ConfigIndentSize};
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, whitespace_string); AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, whitespace_string);
} else { } else {
String16 string = GetString(buffer, pos_range_of_line); String16 string = GetString(buffer, pos_range_of_line);
Int whitespace_len = 0; Int whitespace_len = 0;
for (Int i = 0; i < StyleIndentSize && i < string.len && string.data[i] == ' '; i += 1) { for (Int i = 0; i < ConfigIndentSize && i < string.len && string.data[i] == ' '; i += 1) {
whitespace_len += 1; whitespace_len += 1;
} }

View File

@@ -8,8 +8,8 @@ Window *CreateWind() {
w->font = &PrimaryFont; w->font = &PrimaryFont;
w->visible = true; w->visible = true;
w->layout = true; w->layout = true;
w->draw_scrollbar = StyleDrawScrollbar; w->draw_scrollbar = ConfigDrawScrollbar;
w->draw_line_numbers = StyleDrawLineNumbers; w->draw_line_numbers = ConfigDrawLineNumbers;
w->draw_line_highlight = true; w->draw_line_highlight = true;
w->jump_history = true; w->jump_history = true;
w->id = AllocWindowID(w); w->id = AllocWindowID(w);
@@ -257,7 +257,7 @@ void GotoBackward(Window *window) {
if (window->goto_history.len) { if (window->goto_history.len) {
GotoCrumb *next = GetLast(window->goto_history); GotoCrumb *next = GetLast(window->goto_history);
if (c.time - next->time <= StyleUndoMergeTimeout) { if (c.time - next->time <= ConfigUndoMergeTimeout) {
GotoBackward(window); GotoBackward(window);
} }
} }
@@ -277,7 +277,7 @@ void GotoForward(Window *window) {
if (window->goto_redo.len) { if (window->goto_redo.len) {
GotoCrumb *next = GetLast(window->goto_redo); GotoCrumb *next = GetLast(window->goto_redo);
if (c.time - next->time <= StyleUndoMergeTimeout) { if (c.time - next->time <= ConfigUndoMergeTimeout) {
GotoForward(window); GotoForward(window);
} }
} }

View File

@@ -55,19 +55,29 @@ void CommandWindowUpdate() {
} }
void Command_ShowCommands() { void Command_ShowCommands() {
if (ActiveWindowID == CommandBarWindowID && LastExecutedCommand == Command_ShowCommands) {
ActiveWindowID = LastActiveLayoutWindowID;
return;
}
BSet command_bar = GetBSet(CommandBarWindowID); BSet command_bar = GetBSet(CommandBarWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = true; command_bar.window->eval_command = true;
ActiveWindowID = command_bar.window->id; ActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer); ResetBuffer(command_bar.buffer);
For(CommandFunctions) { For(CommandFunctions) {
Appendf(command_bar.view, "%S\n", it.name); RawAppendf(command_bar.buffer, "%S\n", it.name);
} }
command_bar.view->update_scroll = true; command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer)); SelectRange(command_bar.view, GetBufferEndAsRange(command_bar.buffer));
} RegisterCommand(Command_ShowCommands, "ctrl-shift-p"); } RegisterCommand(Command_ShowCommands, "ctrl-shift-p");
void Command_ShowBufferList() { void Command_ShowBufferList() {
if (ActiveWindowID == CommandBarWindowID && LastExecutedCommand == Command_ShowBufferList) {
ActiveWindowID = LastActiveLayoutWindowID;
return;
}
BSet command_bar = GetBSet(CommandBarWindowID); BSet command_bar = GetBSet(CommandBarWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = false; command_bar.window->eval_command = false;