diff options
| author | Albert Cervin <albert@acervin.com> | 2024-01-29 23:34:07 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2024-01-30 15:04:44 +0100 |
| commit | dda591fa33ac10c433289aa3ee862c3ded41eed3 (patch) | |
| tree | 9a25edbc810fd5d8fbc20f367c71ebcd81bb6026 /src/dged/text.c | |
| parent | 880199011075afd4f2d9bd16c7ce42a04741b5b7 (diff) | |
| download | dged-dda591fa33ac10c433289aa3ee862c3ded41eed3.tar.gz dged-dda591fa33ac10c433289aa3ee862c3ded41eed3.tar.xz dged-dda591fa33ac10c433289aa3ee862c3ded41eed3.zip | |
Syntax highlight is a go
Diffstat (limited to 'src/dged/text.c')
| -rw-r--r-- | src/dged/text.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/dged/text.c b/src/dged/text.c index 4d9a073..bc2b1fc 100644 --- a/src/dged/text.c +++ b/src/dged/text.c @@ -101,6 +101,26 @@ uint32_t text_byteindex_to_col(struct text *text, uint32_t line, return byteidx_to_charidx(&text->lines[line], byteindex); } +uint32_t text_global_idx(struct text *text, uint32_t line, uint32_t col) { + uint32_t byteoff = 0; + uint32_t nlines = text_num_lines(text); + for (uint32_t l = 0; l < line && l < nlines; ++l) { + byteoff += text_line_size(text, l) + 1; + } + + uint32_t l = line < nlines ? line : nlines - 1; + uint32_t nchars = text_line_length(text, l); + uint32_t c = col < nchars ? col : nchars; + byteoff += text_col_to_byteindex(text, l, c); + + if (col > nchars) { + // account for newline + ++byteoff; + } + + return byteoff; +} + void append_empty_lines(struct text *text, uint32_t numlines) { if (text->nlines + numlines >= text->capacity) { |
