From 4a29986fade6c81177dff812ddba69a598a010d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Wed, 22 Apr 2020 20:23:46 -0300 Subject: Separate gap edition from point edition --- page.c | 13 +++++++++++++ point.c | 11 +++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/page.c b/page.c index 9a712ed..856cdfc 100644 --- a/page.c +++ b/page.c @@ -65,3 +65,16 @@ void move_gap_backward(struct page *page) { page->gap_start--; page->elements[page->gap_end] = page->elements[page->gap_start]; } + +void insert_at_gap(struct page *page, uint8_t c) { + page->elements[page->gap_start] = c; + page->gap_start++; + page->element_count++; +} + +void delete_at_gap(struct page *page) { + if (page->gap_start) { + page->gap_start--; + page->element_count--; + } +} diff --git a/point.c b/point.c index 8413ad8..7250f2d 100644 --- a/point.c +++ b/point.c @@ -60,9 +60,7 @@ void insert_at_point(struct point *point, uint8_t c) { } } align_gap(point); - point->page->elements[point->page->gap_start] = c; - point->page->gap_start++; - point->page->element_count++; + insert_at_gap(point->page, c); move_point_forward(point); } @@ -79,9 +77,6 @@ void delete_at_point(struct point *point) { } } align_gap(point); - if (point->page->gap_start != 0) { - point->page->gap_start--; - point->page->element_count--; - move_point_backward(point); - } + delete_at_gap(point->page); + move_point_backward(point); } -- cgit v1.2.3