summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-20 03:46:34 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-20 03:57:51 -0300
commitf3105a3f5365099a7179958092ec2a8eabebbd0c (patch)
tree1276e03420490787535a5b9f8bedc9677fdf994b
parent09062c839b561249730ebb2b67cdf47f36f4c542 (diff)
downloadjet-f3105a3f5365099a7179958092ec2a8eabebbd0c.tar.gz
jet-f3105a3f5365099a7179958092ec2a8eabebbd0c.zip
Implement insert_at_point
-rw-r--r--page.c17
1 files changed, 13 insertions, 4 deletions
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) {