blob: 2f308f9e20a2e5f53a93e921e3fc539072e58f7c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "vec.h"
#include <stdbool.h>
#include <stdint.h>
enum undo_record_type {
Undo_Boundary = 1,
Undo_Add = 2,
Undo_Delete = 3,
};
struct position {
uint32_t row;
uint32_t col;
};
struct undo_boundary {
bool save_point;
};
struct undo_add {
struct position begin;
struct position end;
};
struct undo_delete {
struct position pos;
uint8_t *data;
uint32_t nbytes;
};
struct undo_record {
enum undo_record_type type;
union undo_record_data {
struct undo_boundary boundary;
struct undo_add add;
struct undo_delete delete;
} data;
};
#define INVALID_TOP (uint32_t) - 1
struct undo_stack {
VEC(struct undo_record) records;
uint32_t top;
bool undo_in_progress;
};
void undo_init(struct undo_stack *undo, uint32_t initial_capacity);
void undo_clear(struct undo_stack *undo);
void undo_destroy(struct undo_stack *undo);
uint32_t undo_push_boundary(struct undo_stack *undo,
struct undo_boundary boundary);
uint32_t undo_push_add(struct undo_stack *undo, struct undo_add add);
uint32_t undo_push_delete(struct undo_stack *undo, struct undo_delete delete);
void undo_begin(struct undo_stack *undo);
void undo_next(struct undo_stack *undo, struct undo_record **records_out,
uint32_t *nrecords_out);
void undo_end(struct undo_stack *undo);
uint32_t undo_size(struct undo_stack *undo);
uint32_t undo_current_position(struct undo_stack *undo);
const char *undo_dump(struct undo_stack *undo);
|