Major codebase cleanup and overhaul.

+ editor removes per-buffer fields.
+ switching from internal use of 'int' to 'size_t'.
+ deleting old code
+ double checking relevancy of comments. A lot has changed in
  5 years, even more so in the past week.
+ fixing a few vestigal memory errors from the overhaul.
+ fixing search behavior
This commit is contained in:
2025-11-28 11:31:40 -08:00
parent 7b20e9ee37
commit a9bcb0d36b
13 changed files with 937 additions and 1005 deletions

42
undo.c
View File

@@ -1,8 +1,10 @@
#include <assert.h>
#include <stdlib.h>
#include "abuf.h"
#include "undo.h"
undo_node
undo_node *
undo_node_new(undo_kind kind)
{
undo_node *node = NULL;
@@ -13,10 +15,12 @@ undo_node_new(undo_kind kind)
node->kind = kind;
node->row = node->col = 0;
abuf_init(node->text);
ab_init(&node->text);
node->next = NULL;
node->parent = NULL;
return node;
}
@@ -26,11 +30,10 @@ undo_node_free(undo_node *node)
undo_node *next = NULL;
if (node == NULL) {
return NULL;
return;
}
abuf_free(node-text);
next = node->next;
ab_free(&node->text);
}
@@ -44,9 +47,10 @@ undo_node_free_all(undo_node *node)
}
while (node != NULL) {
next = node->next;
undo_node_free(node);
free(node);
node = node->next;
node = next;
}
}
@@ -65,7 +69,7 @@ undo_tree_init(undo_tree *tree)
void
undo_tree_free(undo_tree *tree)
{
assert(tree == NULL);
assert(tree != NULL);
undo_node_free(tree->pending);
undo_node_free_all(tree->root);
@@ -86,19 +90,25 @@ undo_begin(undo_tree *tree, undo_kind kind)
undo_commit(tree);
}
pending = undo_new_new(kind);
pending = undo_node_new(kind);
assert(pending != NULL);
tree->pending = pending;
}
void undo_prepend(abuf *buf);
void undo_append(buf *buf);
void undo_prependch(char c);
void undo_appendch(char c);
void undo_commit(void);
void undo_apply(undo_node *node);
void editor_undo(void);
void editor_redo(void);
void
undo_prepend(undo_tree *tree, abuf *buf)
{
}
void undo_append(undo_tree *tree, abuf *buf);
void undo_prependch(undo_tree *tree, char c);
void undo_appendch(undo_tree *tree, char c);
void undo_commit(undo_tree *tree);
void undo_apply(struct editor *editor);
void editor_undo(undo_tree *tree);
void editor_redo(undo_tree *tree);