Compare commits

..

2 Commits

Author SHA1 Message Date
Krzosa Karol
c970c1c7d6 UndoEdit, RedoEdit fix recursion, search buffers uses temp buffers now 2026-01-17 08:22:32 +01:00
Krzosa Karol
01488e4eca Search all temp buffers opens a new buffer 2026-01-17 08:03:13 +01:00
4 changed files with 56 additions and 60 deletions

View File

@@ -898,53 +898,61 @@ void SaveHistoryBeforeApplyEdits(Buffer *buffer, Array<HistoryEntry> *stack, Arr
API void RedoEdit(Buffer *buffer, Array<Caret> *carets) {
ProfileFunction();
if (buffer->no_history) return;
if (buffer->redo_stack.len <= 0) return;
HistoryEntry entry = Pop(&buffer->redo_stack);
for (int i = 0; buffer->redo_stack.len > 0; i += 1) {
HistoryEntry entry = Pop(&buffer->redo_stack);
HistoryEntry *e = SaveHistoryBeforeMergeCursor(buffer, &buffer->undo_stack, *carets);
e->time = entry.time;
SaveHistoryBeforeApplyEdits(buffer, &buffer->undo_stack, entry.edits);
ApplyEditsMultiCursor(buffer, entry.edits);
HistoryEntry *e = SaveHistoryBeforeMergeCursor(buffer, &buffer->undo_stack, *carets);
e->time = entry.time;
SaveHistoryBeforeApplyEdits(buffer, &buffer->undo_stack, entry.edits);
ApplyEditsMultiCursor(buffer, entry.edits);
Dealloc(carets);
*carets = entry.carets;
Dealloc(carets);
*carets = entry.carets;
Allocator sys_allocator = GetSystemAllocator();
For(entry.edits) Dealloc(sys_allocator, it.string.data);
Dealloc(&entry.edits);
Allocator sys_allocator = GetSystemAllocator();
For(entry.edits) Dealloc(sys_allocator, it.string.data);
Dealloc(&entry.edits);
if (buffer->redo_stack.len > 0) {
HistoryEntry *next = GetLast(buffer->redo_stack);
if ((next->time - entry.time) <= UndoMergeTime) {
RedoEdit(buffer, carets);
if (buffer->redo_stack.len > 0) {
HistoryEntry *next = GetLast(buffer->redo_stack);
if ((next->time - entry.time) <= UndoMergeTime) {
continue;
}
}
break;
}
}
API void UndoEdit(Buffer *buffer, Array<Caret> *carets) {
ProfileFunction();
if (buffer->no_history) return;
if (buffer->undo_stack.len <= 0) return;
HistoryEntry entry = Pop(&buffer->undo_stack);
HistoryEntry *e = SaveHistoryBeforeMergeCursor(buffer, &buffer->redo_stack, *carets);
e->time = entry.time;
SaveHistoryBeforeApplyEdits(buffer, &buffer->redo_stack, entry.edits);
ApplyEditsMultiCursor(buffer, entry.edits);
static bool warning_reported;
for (int i = 0;buffer->undo_stack.len > 0; i += 1) {
HistoryEntry entry = Pop(&buffer->undo_stack);
HistoryEntry *e = SaveHistoryBeforeMergeCursor(buffer, &buffer->redo_stack, *carets);
e->time = entry.time;
SaveHistoryBeforeApplyEdits(buffer, &buffer->redo_stack, entry.edits);
ApplyEditsMultiCursor(buffer, entry.edits);
Dealloc(carets);
*carets = entry.carets;
Dealloc(carets);
*carets = entry.carets;
Allocator sys_allocator = GetSystemAllocator();
For(entry.edits) Dealloc(sys_allocator, it.string.data);
Dealloc(&entry.edits);
Allocator sys_allocator = GetSystemAllocator();
For(entry.edits) Dealloc(sys_allocator, it.string.data);
Dealloc(&entry.edits);
if (buffer->undo_stack.len > 0) {
HistoryEntry *next = GetLast(buffer->undo_stack);
if ((entry.time - next->time) <= UndoMergeTime) {
UndoEdit(buffer, carets);
if (i > 1000 && !warning_reported) {
ReportConsolef("WARNING: Undoing more then 1000 edits at once, optimizations is needed I think, too much memory usage?");
warning_reported = true;
}
if (buffer->undo_stack.len > 0) {
HistoryEntry *next = GetLast(buffer->undo_stack);
if ((entry.time - next->time) <= UndoMergeTime) {
continue;
}
}
break;
}
}

View File

@@ -443,13 +443,13 @@ BSet Open(Window *window, String path, ResolveOpenMeta meta, bool set_active = t
#if PLUGIN_DIRECTORY_NAVIGATION
OpenDirectoryNavigation(view);
#endif
} else {
Buffer *buffer = GetBuffer(view->active_buffer);
if (o.line != -1) {
if (o.col == -1) o.col = 1;
Int pos = XYToPos(buffer, {o.col - 1, o.line - 1});
SelectRange(view, MakeCaret(pos));
}
}
Buffer *buffer = GetBuffer(view->active_buffer);
if (o.line != -1) {
if (o.col == -1) o.col = 1;
Int pos = XYToPos(buffer, {o.col - 1, o.line - 1});
SelectRange(view, MakeCaret(pos));
}
CenterView(window->id);
} else if (o.kind == OpenKind_Exec) {

View File

@@ -1,8 +1,6 @@
BufferID SearchOpenBuffersBufferID;
struct SearchOpenBuffersParams {
String16 needle;
BufferID buffer;
ViewID view;
};
void Coro_SearchOpenBuffers(mco_coro *co) {
@@ -27,7 +25,7 @@ void Coro_SearchOpenBuffers(mco_coro *co) {
{
Scratch scratch;
Array<Caret> occurences = FindAll(scratch, it, param->needle);
Buffer *out_buffer = GetBuffer(param->buffer);
View *out_view = GetView(param->view);
ForItem (caret, occurences) {
Int pos = caret.range.min;
Int line = PosToLine(it, pos);
@@ -35,7 +33,7 @@ void Coro_SearchOpenBuffers(mco_coro *co) {
Int column = pos - range.min;
String16 line_string = GetString(it, range);
String line_string8 = ToString(scratch, line_string);
RawAppendf(out_buffer, "%S ||> %S:%lld:%lld\n", line_string8, it->name, (long long)line + 1, (long long)column + 1);
Appendf(out_view, "%S ||> %S:%lld:%lld\n", line_string8, it->name, (long long)line + 1, (long long)column + 1);
}
}
CoYield(co);
@@ -50,7 +48,6 @@ void UpdateSearchOpenBuffersView() {
if (active.view->prev_search_line_hash != hash) {
active.view->prev_search_line_hash = hash;
if (line_string.len > 0) {
// @todo: do we reintroduce history here? like in fuzzy search view
Caret caret = active.view->carets[0];
SelectEntireBuffer(active.view);
Replace(active.view, line_string);
@@ -60,7 +57,7 @@ void UpdateSearchOpenBuffersView() {
CoData *dat = CoAdd(Coro_SearchOpenBuffers);
SearchOpenBuffersParams *param = AllocType(dat->arena, SearchOpenBuffersParams);
param->needle = Copy16(dat->arena, line_string);
param->buffer = active.buffer->id;
param->view = active.view->id;
dat->user_ctx = param;
dat->dont_wait_until_resolved = true;
CoResume(dat);
@@ -78,10 +75,8 @@ void CMD_SearchOpenBuffers() {
}
NextActiveWindowID = main.window->id;
Buffer *search_project_buffer = GetBuffer(SearchOpenBuffersBufferID);
View *view = WindowOpenBufferView(main.window, search_project_buffer->name);
view->special = true;
AddCommand(&view->commands, "Open", "ctrl-q | enter | f12", []() {
JumpTempBuffer(&main);
AddCommand(&main.view->commands, "Open", "ctrl-q | enter | f12", []() {
BSet active = GetBSet(ActiveWindowID);
BSet main = GetBSet(PrimaryWindowID);
NextActiveWindowID = main.window->id;
@@ -90,10 +85,10 @@ void CMD_SearchOpenBuffers() {
main.window->goto_list_pos = active.view->carets[0].range.min;
Open(string);
});
view->update_hook = UpdateSearchOpenBuffersView;
main.view->update_hook = UpdateSearchOpenBuffersView;
if (string.len) {
SelectRange(view, GetLineRangeWithoutNL(search_project_buffer, 0));
Replace(view, string);
SelectRange(main.view, GetLineRangeWithoutNL(main.buffer, 0));
Replace(main.view, string);
}
SelectRange(view, GetLineRangeWithoutNL(search_project_buffer, 0));
SelectRange(main.view, GetLineRangeWithoutNL(main.buffer, 0));
} RegisterCommand(CMD_SearchOpenBuffers, "ctrl-shift-f", "Interactive search over the entire project in a new buffer view");

View File

@@ -962,13 +962,6 @@ int main(int argc, char **argv)
EventBuffer->no_history = true;
EventBuffer->special = true;
#endif
#if PLUGIN_SEARCH_OPEN_BUFFERS
Buffer *search_project = CreateBuffer(sys_allocator, GetUniqueBufferName(ProjectDirectory, "search_project"));
search_project->no_history = true;
search_project->special = true;
SearchOpenBuffersBufferID = search_project->id;
#endif
}
InitRender();