From f3105a3f5365099a7179958092ec2a8eabebbd0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 20 Apr 2020 03:46:34 -0300 Subject: Implement insert_at_point --- page.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'page.c') diff --git a/page.c b/page.c index a0e2577..5c0bc0a 100644 --- a/page.c +++ b/page.c @@ -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) { -- cgit v1.2.3