Compare commits
3 Commits
507bd57854
...
05d5de4b7d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05d5de4b7d | ||
|
|
e575569d8a | ||
|
|
4c9c0e5210 |
@@ -1142,6 +1142,7 @@ API void InitBuffer(Allocator allocator, Buffer *buffer, BufferID id = {}, Strin
|
|||||||
API void DeinitBuffer(Buffer *buffer) {
|
API void DeinitBuffer(Buffer *buffer) {
|
||||||
Allocator allocator = buffer->line_starts.allocator;
|
Allocator allocator = buffer->line_starts.allocator;
|
||||||
Dealloc(allocator, buffer->data);
|
Dealloc(allocator, buffer->data);
|
||||||
|
Dealloc(&buffer->hooks);
|
||||||
Dealloc(&buffer->line_starts);
|
Dealloc(&buffer->line_starts);
|
||||||
DeallocHistoryArray(&buffer->undo_stack);
|
DeallocHistoryArray(&buffer->undo_stack);
|
||||||
DeallocHistoryArray(&buffer->redo_stack);
|
DeallocHistoryArray(&buffer->redo_stack);
|
||||||
@@ -1548,7 +1549,18 @@ void ReopenBuffer(Buffer *buffer) {
|
|||||||
buffer->dirty = false;
|
buffer->dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicSaveBuffer(Buffer *buffer) {
|
void SaveBuffer(Buffer *buffer) {
|
||||||
|
ProfileFunction();
|
||||||
|
|
||||||
|
For (GlobalHooks) {
|
||||||
|
if (it.kind == HookKind_BeforeSavingBuffer) {
|
||||||
|
ProfileScopeEx(it.name);
|
||||||
|
HookParam param = {};
|
||||||
|
param.buffer = buffer;
|
||||||
|
it.function(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
String string = AllocCharString(scratch, buffer);
|
String string = AllocCharString(scratch, buffer);
|
||||||
bool success = WriteFile(buffer->name, string);
|
bool success = WriteFile(buffer->name, string);
|
||||||
@@ -1561,11 +1573,3 @@ void BasicSaveBuffer(Buffer *buffer) {
|
|||||||
ReportWarningf("Failed to save file with name: %S", buffer->name);
|
ReportWarningf("Failed to save file with name: %S", buffer->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveBuffer(Buffer *buffer) {
|
|
||||||
if (TrimTrailingWhitespace) {
|
|
||||||
TrimWhitespace(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
BasicSaveBuffer(buffer);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -291,6 +291,12 @@ void TrimWhitespace(Buffer *buffer, bool trim_lines_with_caret) {
|
|||||||
view->update_scroll = false;
|
view->update_scroll = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HOOK_TrimTrailingWhitespace(HookParam param) {
|
||||||
|
if (TrimTrailingWhitespace) {
|
||||||
|
TrimWhitespace(param.buffer, false);
|
||||||
|
}
|
||||||
|
} RegisterHook(HOOK_TrimTrailingWhitespace, HookKind_BeforeSavingBuffer, "", "Cleans trailing whitespace before saving to file");
|
||||||
|
|
||||||
void ConvertLineEndingsToLF(Buffer *buffer, bool trim_lines_with_caret = false) {
|
void ConvertLineEndingsToLF(Buffer *buffer, bool trim_lines_with_caret = false) {
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
|
|
||||||
@@ -486,7 +492,7 @@ void CMD_SaveAll(HookParam param) {
|
|||||||
For(Buffers) {
|
For(Buffers) {
|
||||||
// NOTE: file_mod_time is only set when buffer got read or written to disk already so should be saved
|
// NOTE: file_mod_time is only set when buffer got read or written to disk already so should be saved
|
||||||
if (it->file_mod_time && it->dirty) {
|
if (it->file_mod_time && it->dirty) {
|
||||||
BasicSaveBuffer(it);
|
SaveBuffer(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} RegisterCommand(CMD_SaveAll, "ctrl-shift-s");
|
} RegisterCommand(CMD_SaveAll, "ctrl-shift-s");
|
||||||
@@ -1106,6 +1112,12 @@ String Coro_CloseAllEx(mco_coro *co) {
|
|||||||
void Coro_Quit(mco_coro *co) {
|
void Coro_Quit(mco_coro *co) {
|
||||||
String res = Coro_CloseAllEx(co);
|
String res = Coro_CloseAllEx(co);
|
||||||
if (res != "Cancel") {
|
if (res != "Cancel") {
|
||||||
|
For (GlobalHooks) {
|
||||||
|
if (it.kind == HookKind_AppQuit) {
|
||||||
|
ProfileScopeEx(it.name);
|
||||||
|
it.function({});
|
||||||
|
}
|
||||||
|
}
|
||||||
AppIsRunning = false;
|
AppIsRunning = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1114,9 +1126,15 @@ void CMD_Quit(HookParam param) {
|
|||||||
CoRemove("Coro_Quit");
|
CoRemove("Coro_Quit");
|
||||||
CoData *data = CoAdd(Coro_Quit);
|
CoData *data = CoAdd(Coro_Quit);
|
||||||
CoResume(data);
|
CoResume(data);
|
||||||
} RegisterHook(CMD_Quit, HookKind_AppQuit, "", "Ask user which files he would like to save and exit");
|
} RegisterCommand(CMD_Quit, "", "Ask user which files he would like to save and exit");
|
||||||
|
|
||||||
void CMD_QuitWithoutSaving(HookParam param) {
|
void CMD_QuitWithoutSaving(HookParam param) {
|
||||||
|
For (GlobalHooks) {
|
||||||
|
if (it.kind == HookKind_AppQuit) {
|
||||||
|
ProfileScopeEx(it.name);
|
||||||
|
it.function({});
|
||||||
|
}
|
||||||
|
}
|
||||||
AppIsRunning = false;
|
AppIsRunning = false;
|
||||||
} RegisterCommand(CMD_QuitWithoutSaving, "", "Self explanatory");
|
} RegisterCommand(CMD_QuitWithoutSaving, "", "Self explanatory");
|
||||||
|
|
||||||
|
|||||||
2249
src/text_editor/remedybg_plugin.cpp
Normal file
2249
src/text_editor/remedybg_plugin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -34,6 +34,8 @@
|
|||||||
#include "draw.cpp"
|
#include "draw.cpp"
|
||||||
#include "test/tests.cpp"
|
#include "test/tests.cpp"
|
||||||
|
|
||||||
|
#include "remedybg_plugin.cpp"
|
||||||
|
|
||||||
#if OS_WASM
|
#if OS_WASM
|
||||||
EM_JS(void, JS_SetMouseCursor, (const char *cursor_str), {
|
EM_JS(void, JS_SetMouseCursor, (const char *cursor_str), {
|
||||||
document.getElementById("canvas").style.cursor = UTF8ToString(cursor_str);
|
document.getElementById("canvas").style.cursor = UTF8ToString(cursor_str);
|
||||||
@@ -425,12 +427,7 @@ void OnCommand(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.kind == EVENT_QUIT) {
|
if (event.kind == EVENT_QUIT) {
|
||||||
For (GlobalHooks) {
|
CMD_Quit({});
|
||||||
if (it.kind == HookKind_AppQuit) {
|
|
||||||
ProfileScopeEx(it.name);
|
|
||||||
it.function({});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IF_DEBUG(AssertRanges(main.view->carets));
|
IF_DEBUG(AssertRanges(main.view->carets));
|
||||||
@@ -511,6 +508,7 @@ void GarbageCollect() {
|
|||||||
|
|
||||||
RawAppendf(GCInfoBuffer, "View %d %S\n", (int)it->id.id, buffer ? buffer->name : String{"NULL"});
|
RawAppendf(GCInfoBuffer, "View %d %S\n", (int)it->id.id, buffer ? buffer->name : String{"NULL"});
|
||||||
remove_item = true;
|
remove_item = true;
|
||||||
|
Dealloc(&it->hooks);
|
||||||
Dealloc(it);
|
Dealloc(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,66 @@ struct HistoryEntry {
|
|||||||
double time;
|
double time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum HookKind {
|
||||||
|
HookKind_Invalid,
|
||||||
|
|
||||||
|
HookKind_AppInit,
|
||||||
|
HookKind_AppUpdate,
|
||||||
|
HookKind_AppQuit,
|
||||||
|
|
||||||
|
// Should we have commands like PostCommand, PreCommand? what would be the purpose?
|
||||||
|
HookKind_Command,
|
||||||
|
|
||||||
|
// Currently we are only basically allowing control over non-layouted windows.
|
||||||
|
// How can this be expanded?
|
||||||
|
// - Changing the layout algorithm: this seems like a decent one
|
||||||
|
// - What beside that?
|
||||||
|
HookKind_HandleWindowLayout,
|
||||||
|
|
||||||
|
// Move the special window rendering to hooks?
|
||||||
|
// HookKind_RenderWindow,
|
||||||
|
// HookKind_CreateWindow,
|
||||||
|
|
||||||
|
// How to handle formatters for multiple languages and other saving rules???
|
||||||
|
HookKind_BeforeSavingBuffer,
|
||||||
|
HookKind_CreateBuffer,
|
||||||
|
// HookKind_BufferSave,
|
||||||
|
// HookKind_AfterBufferSave,
|
||||||
|
|
||||||
|
// HookKind_ResolveOpen,
|
||||||
|
|
||||||
|
// HookKind_BeforeBufferOpen,
|
||||||
|
// HookKind_BufferOpen,
|
||||||
|
// HookKind_AfterBufferOpen,
|
||||||
|
|
||||||
|
HookKind_CreateView,
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Global hooks, per (window, view, buffer) hooks
|
||||||
|
|
||||||
|
struct HookParam {
|
||||||
|
union {
|
||||||
|
Buffer *buffer;
|
||||||
|
struct {
|
||||||
|
Window *window;
|
||||||
|
Rect2I *rect;
|
||||||
|
int16_t wx;
|
||||||
|
int16_t wy;
|
||||||
|
} layout;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void HookFunction(HookParam param);
|
||||||
|
struct Hook {
|
||||||
|
HookKind kind;
|
||||||
|
String name;
|
||||||
|
String docs;
|
||||||
|
HookFunction *function;
|
||||||
|
String binding;
|
||||||
|
struct Trigger *trigger;
|
||||||
|
};
|
||||||
|
|
||||||
struct Buffer {
|
struct Buffer {
|
||||||
BufferID id;
|
BufferID id;
|
||||||
String name;
|
String name;
|
||||||
@@ -44,6 +104,7 @@ struct Buffer {
|
|||||||
Array<HistoryEntry> undo_stack;
|
Array<HistoryEntry> undo_stack;
|
||||||
Array<HistoryEntry> redo_stack;
|
Array<HistoryEntry> redo_stack;
|
||||||
int edit_phase;
|
int edit_phase;
|
||||||
|
Array<Hook> hooks;
|
||||||
struct {
|
struct {
|
||||||
unsigned no_history : 1;
|
unsigned no_history : 1;
|
||||||
unsigned no_line_starts : 1;
|
unsigned no_line_starts : 1;
|
||||||
@@ -57,58 +118,6 @@ struct Buffer {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
enum HookKind {
|
|
||||||
HookKind_Invalid,
|
|
||||||
|
|
||||||
HookKind_AppInit,
|
|
||||||
HookKind_AppUpdate,
|
|
||||||
HookKind_AppQuit,
|
|
||||||
|
|
||||||
// Should we have commands like PostCommand, PreCommand? what would be the purpose?
|
|
||||||
HookKind_Command,
|
|
||||||
|
|
||||||
|
|
||||||
// Currently we are only basically allowing control over non-layouted windows.
|
|
||||||
// How can this be expanded?
|
|
||||||
// - Changing the layout algorithm: this seems like a decent one
|
|
||||||
// - What beside that?
|
|
||||||
HookKind_LayoutWindow,
|
|
||||||
HookKind_RenderWindow
|
|
||||||
|
|
||||||
HookKind_BeforeBufferSave,
|
|
||||||
HookKind_BufferSave,
|
|
||||||
HookKind_AfterBufferSave,
|
|
||||||
|
|
||||||
HookKind_BeforeBufferOpen,
|
|
||||||
HookKind_BufferOpen,
|
|
||||||
HookKind_AfterBufferOpen,
|
|
||||||
|
|
||||||
HookKind_ViewUpdate,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Global hooks, per (window, view, buffer) hooks
|
|
||||||
|
|
||||||
struct HookParam {
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
Window *window;
|
|
||||||
Rect2I *rect;
|
|
||||||
int16_t wx;
|
|
||||||
int16_t wy;
|
|
||||||
} layout;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void HookFunction(HookParam param);
|
|
||||||
struct Hook {
|
|
||||||
HookKind kind;
|
|
||||||
String name;
|
|
||||||
String docs;
|
|
||||||
HookFunction *function;
|
|
||||||
String binding;
|
|
||||||
struct Trigger *trigger;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct View {
|
struct View {
|
||||||
ViewID id;
|
ViewID id;
|
||||||
BufferID active_buffer;
|
BufferID active_buffer;
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ void LayoutWindows(int16_t wx, int16_t wy) {
|
|||||||
|
|
||||||
ForItem (n, Windows) {
|
ForItem (n, Windows) {
|
||||||
ForItem (hook, n->hooks) {
|
ForItem (hook, n->hooks) {
|
||||||
if (hook.kind == HookKind_LayoutWindow) {
|
if (hook.kind == HookKind_HandleWindowLayout) {
|
||||||
ProfileScopeEx(it.name);
|
ProfileScopeEx(it.name);
|
||||||
HookParam param = {};
|
HookParam param = {};
|
||||||
param.layout.window = n;
|
param.layout.window = n;
|
||||||
|
|||||||
@@ -35,5 +35,5 @@ void InitBuildWindow(HookParam param) {
|
|||||||
window->visible = false;
|
window->visible = false;
|
||||||
window->lose_visibility_on_escape = true;
|
window->lose_visibility_on_escape = true;
|
||||||
window->jump_history = false;
|
window->jump_history = false;
|
||||||
AddHook(&window->hooks, HookKind_LayoutWindow, "LayoutBuildWindow", "", LayoutBuildWindow);
|
AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutBuildWindow", "", LayoutBuildWindow);
|
||||||
} RegisterHook(InitBuildWindow, HookKind_AppInit, "", "Init the build window");
|
} RegisterHook(InitBuildWindow, HookKind_AppInit, "", "Init the build window");
|
||||||
|
|||||||
@@ -248,5 +248,5 @@ void InitCommandWindow(HookParam param) {
|
|||||||
window->sync_visibility_with_focus = true;
|
window->sync_visibility_with_focus = true;
|
||||||
window->lose_focus_on_escape = true;
|
window->lose_focus_on_escape = true;
|
||||||
window->jump_history = false;
|
window->jump_history = false;
|
||||||
AddHook(&window->hooks, HookKind_LayoutWindow, "LayoutCommandWindow", "", LayoutCommandWindow);
|
AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutCommandWindow", "", LayoutCommandWindow);
|
||||||
} RegisterHook(InitCommandWindow, HookKind_AppInit, "", "Init command window");
|
} RegisterHook(InitCommandWindow, HookKind_AppInit, "", "Init command window");
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ void InitDebugWindow(HookParam param) {
|
|||||||
window->active_view = view->id;
|
window->active_view = view->id;
|
||||||
window->visible = false;
|
window->visible = false;
|
||||||
|
|
||||||
AddHook(&window->hooks, HookKind_LayoutWindow, "@todo: LayoutDebugWindow", "", LayoutDebugWindow);
|
AddHook(&window->hooks, HookKind_HandleWindowLayout, "@todo: LayoutDebugWindow", "", LayoutDebugWindow);
|
||||||
} RegisterHook(InitDebugWindow, HookKind_AppInit, "", "Init the debug window");
|
} RegisterHook(InitDebugWindow, HookKind_AppInit, "", "Init the debug window");
|
||||||
|
|
||||||
void CMD_ToggleDebug(HookParam param) {
|
void CMD_ToggleDebug(HookParam param) {
|
||||||
|
|||||||
@@ -99,5 +99,5 @@ void InitSearchWindow(HookParam param) {
|
|||||||
AddCommand(&view->hooks, "SearchAll", "alt-enter", CMD_SearchAll);
|
AddCommand(&view->hooks, "SearchAll", "alt-enter", CMD_SearchAll);
|
||||||
AddCommand(&view->hooks, "SearchPrevInSearch", "shift-enter", CMD_SearchPrevInSearch);
|
AddCommand(&view->hooks, "SearchPrevInSearch", "shift-enter", CMD_SearchPrevInSearch);
|
||||||
AddCommand(&view->hooks, "SearchNextInSearch", "enter", CMD_SearchNextInSearch);
|
AddCommand(&view->hooks, "SearchNextInSearch", "enter", CMD_SearchNextInSearch);
|
||||||
AddHook(&window->hooks, HookKind_LayoutWindow, "LayoutSearchWindow", "", LayoutSearchWindow);
|
AddHook(&window->hooks, HookKind_HandleWindowLayout, "LayoutSearchWindow", "", LayoutSearchWindow);
|
||||||
} RegisterHook(InitSearchWindow, HookKind_AppInit, "", "Init the search window");
|
} RegisterHook(InitSearchWindow, HookKind_AppInit, "", "Init the search window");
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ void LayoutStatusWindow(HookParam param) {
|
|||||||
}
|
}
|
||||||
Int barsize = GetExpandingBarSize(p.window);
|
Int barsize = GetExpandingBarSize(p.window);
|
||||||
p.window->document_rect = p.window->total_rect = CutBottom(p.rect, barsize);
|
p.window->document_rect = p.window->total_rect = CutBottom(p.rect, barsize);
|
||||||
} RegisterHook(LayoutStatusWindow, HookKind_LayoutWindow, "", "Layout the status window");
|
} RegisterHook(LayoutStatusWindow, HookKind_HandleWindowLayout, "", "Layout the status window");
|
||||||
|
|
||||||
void StatusWindowInit(HookParam param) {
|
void StatusWindowInit(HookParam param) {
|
||||||
Window *window = CreateWind();
|
Window *window = CreateWind();
|
||||||
@@ -95,5 +95,5 @@ void StatusWindowInit(HookParam param) {
|
|||||||
window->primary = false;
|
window->primary = false;
|
||||||
window->jump_history = false;
|
window->jump_history = false;
|
||||||
window->lose_focus_on_escape = true;
|
window->lose_focus_on_escape = true;
|
||||||
AddHook(&window->hooks, HookKind_LayoutWindow, "@todo LayoutStatusWindow", "", LayoutStatusWindow);
|
AddHook(&window->hooks, HookKind_HandleWindowLayout, "@todo LayoutStatusWindow", "", LayoutStatusWindow);
|
||||||
} RegisterHook(StatusWindowInit, HookKind_AppInit, "", "Init the status window");
|
} RegisterHook(StatusWindowInit, HookKind_AppInit, "", "Init the status window");
|
||||||
Reference in New Issue
Block a user