diff options
| author | Albert Cervin <albert@acervin.com> | 2023-04-06 23:23:46 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-05-01 22:19:14 +0200 |
| commit | a123725a12e948d78badb2cb686d38548f1c633b (patch) | |
| tree | c92c46134ef5536fbbf3bf08983c4f0dea1aaf58 /src/dged/text.h | |
| parent | b5ed4cf757afc50afb6ac499eee7b87a2648fa4c (diff) | |
| download | dged-a123725a12e948d78badb2cb686d38548f1c633b.tar.gz dged-a123725a12e948d78badb2cb686d38548f1c633b.tar.xz dged-a123725a12e948d78badb2cb686d38548f1c633b.zip | |
Implement window handling
Also implement searching.
fix undo boundaries
when it checked for other save point, it used && instead of == which
caused it to overwrite other types.
Fix bytes vs chars bug in text_get_region
Diffstat (limited to 'src/dged/text.h')
| -rw-r--r-- | src/dged/text.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/dged/text.h b/src/dged/text.h new file mode 100644 index 0000000..fbee89b --- /dev/null +++ b/src/dged/text.h @@ -0,0 +1,54 @@ +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +// opaque so it is easier to change representation to gap, rope etc. +struct text; + +struct render_command; + +struct text *text_create(uint32_t initial_capacity); +void text_destroy(struct text *text); + +/** + * Clear the text without reclaiming memory + */ +void text_clear(struct text *text); + +void text_insert_at(struct text *text, uint32_t line, uint32_t col, + uint8_t *bytes, uint32_t nbytes, uint32_t *lines_added, + uint32_t *cols_added); + +void text_append(struct text *text, uint8_t *bytes, uint32_t nbytes, + uint32_t *lines_added, uint32_t *cols_added); + +void text_delete(struct text *text, uint32_t start_line, uint32_t start_col, + uint32_t end_line, uint32_t end_col); + +uint32_t text_num_lines(struct text *text); +uint32_t text_line_length(struct text *text, uint32_t lineidx); +uint32_t text_line_size(struct text *text, uint32_t lineidx); +uint32_t text_col_to_byteindex(struct text *text, uint32_t line, uint32_t col); +uint32_t text_byteindex_to_col(struct text *text, uint32_t line, + uint32_t byteindex); + +struct text_chunk { + uint8_t *text; + uint32_t nbytes; + uint32_t nchars; + uint32_t line; + bool allocated; +}; + +typedef void (*chunk_cb)(struct text_chunk *chunk, void *userdata); +void text_for_each_line(struct text *text, uint32_t line, uint32_t nlines, + chunk_cb callback, void *userdata); + +void text_for_each_chunk(struct text *text, chunk_cb callback, void *userdata); + +struct text_chunk text_get_line(struct text *text, uint32_t line); +struct text_chunk text_get_region(struct text *text, uint32_t start_line, + uint32_t start_col, uint32_t end_line, + uint32_t end_col); + +bool text_line_contains_unicode(struct text *text, uint32_t line); |
