Compare commits

...

2 Commits

Author SHA1 Message Date
Krzosa Karol
6f9299e557 Misc changes 2025-12-26 21:01:54 +01:00
Krzosa Karol
29ad3a8f08 Checkpoint automation 2025-12-26 20:59:52 +01:00
10 changed files with 58 additions and 55 deletions

View File

@@ -17,12 +17,6 @@ Commands TODO:
- Turned off by default - Turned off by default
- Special: non editable, hotkeys don't work etc. - Special: non editable, hotkeys don't work etc.
- CONSIDER AUTOMATING: CheckpointBeforeGoto
- GotoBackward how to handle that in case we want to automate and create on every move?
- Add jump checkpoints
- Make sure the timing window works forward and backward in undo and jump
backlog backlog
FEATURE Search whole words, case sensitive etc. FEATURE Search whole words, case sensitive etc.
FEATURE Select all searched occurences FEATURE Select all searched occurences

View File

@@ -30,7 +30,7 @@ void BacktraceOnError(void *data, const char *msg, int errnum) {
int BacktraceOnPrint(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) { int BacktraceOnPrint(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) {
bool printed = false; bool printed = false;
if (filename != NULL) { if (filename != NULL) {
char buffer[512]; char buffer[1024];
char *f = realpath(filename, buffer); char *f = realpath(filename, buffer);
printf("%s:%d:1: ", f, lineno); printf("%s:%d:1: ", f, lineno);
printed = true; printed = true;

View File

@@ -975,7 +975,6 @@ API void UndoEdit(Buffer *buffer, Array<Caret> *carets) {
} }
} }
API void DeallocHistoryEntries(Array<HistoryEntry> *entries) { API void DeallocHistoryEntries(Array<HistoryEntry> *entries) {
For(*entries) { For(*entries) {
Dealloc(&it.carets); Dealloc(&it.carets);

View File

@@ -33,7 +33,6 @@ String GetMainDir() {
} }
void JumpGarbageBuffer(BSet *set, String buffer_name = "") { void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
CheckpointBeforeGoto(set->window);
if (buffer_name.len == 0) { if (buffer_name.len == 0) {
buffer_name = GetUniqueBufferName(GetDir(set->buffer), "temp"); buffer_name = GetUniqueBufferName(GetDir(set->buffer), "temp");
} }
@@ -43,7 +42,6 @@ void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
} }
void BeginJump(BSet *set, BufferID buffer_id = NullBufferID) { void BeginJump(BSet *set, BufferID buffer_id = NullBufferID) {
CheckpointBeforeGoto(set->window);
set->buffer = GetBuffer(buffer_id); set->buffer = GetBuffer(buffer_id);
set->view = WindowOpenBufferView(set->window, set->buffer->name); set->view = WindowOpenBufferView(set->window, set->buffer->name);
} }
@@ -444,7 +442,6 @@ BSet Exec(String cmd, String working_dir, bool set_active = true) {
BSet ExecBuild(String cmd) { BSet ExecBuild(String cmd) {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
ActiveWindowID = main.window->id; ActiveWindowID = main.window->id;
CheckpointBeforeGoto(main.window);
View *view = WindowOpenBufferView(main.window, BuildBuffer->name); View *view = WindowOpenBufferView(main.window, BuildBuffer->name);
ResetBuffer(BuildBuffer); ResetBuffer(BuildBuffer);
Exec(view->id, true, cmd, WorkDir); Exec(view->id, true, cmd, WorkDir);
@@ -614,7 +611,6 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
ActiveWindowID = set.window->id; ActiveWindowID = set.window->id;
} }
if (IsDir(o.path)) { if (IsDir(o.path)) {
CheckpointBeforeGoto(set.window);
View *view = WindowOpenBufferView(set.window, o.path); View *view = WindowOpenBufferView(set.window, o.path);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
ResetBuffer(buffer); ResetBuffer(buffer);
@@ -623,7 +619,6 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
RawAppendf(buffer, "%S\n", it.filename); RawAppendf(buffer, "%S\n", it.filename);
} }
} else { } else {
CheckpointBeforeGoto(set.window);
View *view = WindowOpenBufferView(set.window, o.path); View *view = WindowOpenBufferView(set.window, o.path);
Buffer *buffer = GetBuffer(view->active_buffer); Buffer *buffer = GetBuffer(view->active_buffer);
if (o.line != -1) { if (o.line != -1) {
@@ -845,11 +840,13 @@ void Command_CloseAll() {
void Command_GotoBackward() { void Command_GotoBackward() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
main.window->skip_checkpoint = true;
GotoBackward(main.window); GotoBackward(main.window);
} RegisterCommand(Command_GotoBackward, "alt-q | mousex1"); } RegisterCommand(Command_GotoBackward, "alt-q | mousex1");
void Command_GotoForward() { void Command_GotoForward() {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
main.window->skip_checkpoint = true;
GotoForward(main.window); GotoForward(main.window);
} RegisterCommand(Command_GotoForward, "alt-shift-q | mousex2"); } RegisterCommand(Command_GotoForward, "alt-shift-q | mousex2");

View File

@@ -10,7 +10,6 @@ void CoRemove(String name) {
} }
} }
#define CoAdd(x) CoAddEx(x, #x) #define CoAdd(x) CoAddEx(x, #x)
mco_coro *CoAddEx(CoroutineProc *proc, String name) { mco_coro *CoAddEx(CoroutineProc *proc, String name) {
CoRemove(name); CoRemove(name);

View File

@@ -170,10 +170,9 @@ void OnCommand(Event event) {
// //
// Window cursor setting // Window cursor setting
// //
Scratch scratch; Scratch scratch;
Array<Window *> order = GetWindowZOrder(scratch); Array<Window *> order = GetWindowZOrder(scratch);
// Handle wheel scrolling // Handle wheel scrolling
if (event.xwheel || event.ywheel) { if (event.xwheel || event.ywheel) {
Vec2I mouse = MouseVec2I(); Vec2I mouse = MouseVec2I();
@@ -330,8 +329,6 @@ void OnCommand(Event event) {
bool mouse_in_line_numbers = AreOverlapping(mouse, active.window->line_numbers_rect); bool mouse_in_line_numbers = AreOverlapping(mouse, active.window->line_numbers_rect);
if (mouse_in_document || mouse_in_line_numbers) { if (mouse_in_document || mouse_in_line_numbers) {
DocumentSelected = active.window->id; DocumentSelected = active.window->id;
CheckpointBeforeGoto(active.window);
Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse); Int p = ScreenSpaceToBufferPos(active.window, active.view, active.buffer, mouse);
if (Alt()) Insert(&active.view->carets, MakeCaret(p, p), 0); if (Alt()) Insert(&active.view->carets, MakeCaret(p, p), 0);
@@ -502,7 +499,7 @@ void Update(Event event) {
ProfileFunction(); ProfileFunction();
LayoutWindows(event.xwindow, event.ywindow); LayoutWindows(event.xwindow, event.ywindow);
Scratch scratch; Scratch scratch;
Array<Window *> order = GetWindowZOrder(scratch); Array<Window *> order = GetWindowZOrder(scratch);
For(order) { For(order) {
if (!it->visible) { if (!it->visible) {
@@ -513,6 +510,12 @@ void Update(Event event) {
view->update_scroll = true; view->update_scroll = true;
} }
For (Windows) {
if (it->jump_history) {
View *view = GetView(it->active_view);
it->begin_frame_crumb = {it->active_view, view->carets[0], GetTimeSeconds()};
}
}
OnCommand(event); OnCommand(event);
StatusWindowUpdate(); StatusWindowUpdate();
@@ -521,17 +524,37 @@ void Update(Event event) {
SearchWindowUpdate(); SearchWindowUpdate();
UpdateProcesses(); UpdateProcesses();
CoUpdate(&event); CoUpdate(&event);
For (Buffers) it->begin_frame_change_id = it->change_id; // after last place we modify
// We update it here despite the name to make it sure that all the possible changes are
// included albeit with delayed response. If we did this at the beginning of the frame
// and the DebugWindowUpdated we wouldnt get to know that in the OnCommand.
For (Buffers) {
it->begin_frame_change_id = it->change_id;
}
{ {
ProfileScope(WindowEndOfFrameVisibilityAndLastActive); ProfileScope(WindowEndOfFrameVisibilityAndLastActive);
For (Windows) { For (Windows) {
if (it->goto_history.len > ConfigJumpHistorySize) { if (it->jump_history) {
RemoveByIndex(&it->goto_history, 0); View *view = GetView(it->active_view);
} bool are_equal = it->begin_frame_crumb.view_id == it->active_view && AreEqual(view->carets[0], it->begin_frame_crumb.caret);
if (it->goto_redo.len > ConfigJumpHistorySize) { if (!are_equal) {
RemoveByIndex(&it->goto_redo, 0); if (!it->skip_checkpoint) {
Add(&it->goto_history, it->begin_frame_crumb);
it->goto_redo.len = 0;
}
}
it->skip_checkpoint = false;
if (it->goto_history.len > ConfigJumpHistorySize) {
RemoveByIndex(&it->goto_history, 0);
}
if (it->goto_redo.len > ConfigJumpHistorySize) {
RemoveByIndex(&it->goto_redo, 0);
}
} }
if (it->sync_visibility_with_focus) { if (it->sync_visibility_with_focus) {
if (it->id == ActiveWindowID) { if (it->id == ActiveWindowID) {
it->visible = true; it->visible = true;

View File

@@ -1,4 +1,4 @@
inline WindowID AllocWindowID(Window *window) { WindowID AllocWindowID(Window *window) {
return {WindowIDs.id++, window}; return {WindowIDs.id++, window};
} }
@@ -64,16 +64,16 @@ Window *FindWindow(BufferID buffer_id) {
return NULL; return NULL;
} }
inline Window *GetActiveWind() { Window *GetActiveWind() {
return GetWindow(ActiveWindowID); return GetWindow(ActiveWindowID);
} }
inline bool IsDocumentSelectionValid() { bool IsDocumentSelectionValid() {
if (DocumentSelected.id == -1) return false; if (DocumentSelected.id == -1) return false;
return true; return true;
} }
inline bool IsScrollbarSelectionValid() { bool IsScrollbarSelectionValid() {
if (ScrollbarSelected.id == -1) return false; if (ScrollbarSelected.id == -1) return false;
return true; return true;
} }
@@ -235,17 +235,6 @@ Int ScreenSpaceToBufferPosErrorOutOfBounds(Window *window, View *view, Buffer *b
return result; return result;
} }
void CheckpointBeforeGoto(Window *window, View *view) {
if (window->jump_history == false) return;
Add(&window->goto_history, {view->id, view->carets[0], GetTimeSeconds()});
window->goto_redo.len = 0;
}
void CheckpointBeforeGoto(Window *window) {
CheckpointBeforeGoto(window, GetView(window->active_view));
}
GotoCrumb GetCrumb(Array<GotoCrumb> *cr) { GotoCrumb GetCrumb(Array<GotoCrumb> *cr) {
for (; cr->len;) { for (; cr->len;) {
GotoCrumb c = Pop(cr); GotoCrumb c = Pop(cr);

View File

@@ -17,6 +17,7 @@ struct Window {
double weight; double weight;
Caret search_bar_anchor; Caret search_bar_anchor;
GotoCrumb begin_frame_crumb;
Array<GotoCrumb> goto_history; Array<GotoCrumb> goto_history;
Array<GotoCrumb> goto_redo; Array<GotoCrumb> goto_redo;
@@ -24,18 +25,19 @@ struct Window {
Int goto_list_pos; Int goto_list_pos;
struct { struct {
bool draw_scrollbar : 1; uint32_t draw_scrollbar : 1;
bool draw_line_numbers : 1; uint32_t draw_line_numbers : 1;
bool draw_darker : 1; uint32_t draw_darker : 1;
bool draw_line_highlight : 1; uint32_t draw_line_highlight : 1;
bool visible : 1; uint32_t visible : 1;
bool layout : 1; uint32_t layout : 1;
bool close : 1; uint32_t close : 1;
bool sync_visibility_with_focus : 1; uint32_t sync_visibility_with_focus : 1;
bool lose_focus_on_escape : 1; uint32_t lose_focus_on_escape : 1;
bool lose_visibility_on_escape : 1; uint32_t lose_visibility_on_escape : 1;
bool jump_history : 1; uint32_t jump_history : 1;
bool eval_command : 1; uint32_t eval_command : 1;
uint32_t skip_checkpoint : 1;
}; };
}; };

View File

@@ -160,7 +160,7 @@ void Command_ShowBufferList() {
ActiveWindowID = command_bar.window->id; ActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer); ResetBuffer(command_bar.buffer);
For (Buffers) { For (Buffers) {
if (it->special || it->garbage) { if (it->special || it->garbage || it->is_dir) {
continue; continue;
} }
RawAppendf(command_bar.buffer, "\n%S", it->name); RawAppendf(command_bar.buffer, "\n%S", it->name);

View File

@@ -83,11 +83,11 @@ void StatusWindowUpdate() {
// replace data up to separator with filename and stuff // replace data up to separator with filename and stuff
const char *reopen = main.buffer->changed_on_disk ? " Reopen()" : ""; const char *reopen = main.buffer->changed_on_disk ? " :Reopen" : "";
String s = Format(scratch, "# %S:%lld:%lld%s", main.buffer->name, (long long)xy.line + 1ll, (long long)xy.col + 1ll, reopen); String s = Format(scratch, "# %S:%lld:%lld%s", main.buffer->name, (long long)xy.line + 1ll, (long long)xy.col + 1ll, reopen);
For (ActiveProcesses) { For (ActiveProcesses) {
if (it.view_id == main.view->id.id) { if (it.view_id == main.view->id.id) {
s = Format(scratch, "%S %lld Kill()", s, (long long)it.id); s = Format(scratch, "%S %lld :KillProcess", s, (long long)it.id);
} }
} }