diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-20 03:46:34 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-20 03:57:51 -0300 |
commit | f3105a3f5365099a7179958092ec2a8eabebbd0c (patch) | |
tree | 1276e03420490787535a5b9f8bedc9677fdf994b /page.c | |
parent | 09062c839b561249730ebb2b67cdf47f36f4c542 (diff) | |
download | jet-f3105a3f5365099a7179958092ec2a8eabebbd0c.tar.gz jet-f3105a3f5365099a7179958092ec2a8eabebbd0c.zip |
Implement insert_at_point
Diffstat (limited to 'page.c')
-rw-r--r-- | page.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -104,11 +104,20 @@ void move_gap(struct page *page, uint16_t offset) { } } -void insert_into_page(struct page *page, uint8_t c) { - if (page->gap_start != page->gap_end) { - page->buffer[page->gap_start] = c; - page->gap_start++; +void insert_at_point(struct point *point, uint8_t c) { + struct page *page = point->current_page; + if (page->gap_start == page->gap_end) { + split_page(page); + if (point->offset >= PAGE_SIZE / 2) { + point->current_page = point->current_page->next; + point->offset -= PAGE_SIZE / 2; + page = point->current_page; + } } + move_gap(page, point->offset); + page->buffer[page->gap_start] = c; + page->gap_start++; + move_point_forward(point); } void delete_from_page(struct page *page) { |