From 67d8948f37e59b9206e27070d91c7e368c099aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Mon, 21 Jul 2014 13:22:56 +0200 Subject: Add comments regarding deletion --- editor.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'editor.c') diff --git a/editor.c b/editor.c index 4af1e41..567a1e8 100644 --- a/editor.c +++ b/editor.c @@ -255,6 +255,7 @@ static void piece_init(Piece *p, Piece *prev, Piece *next, char *content, size_t p->len = len; } +/* returns the piece holding the text at byte offset pos */ static Location piece_get(Editor *ed, size_t pos) { Location loc = {}; // TODO: handle position at end of file: pos+1 @@ -516,6 +517,20 @@ void editor_iterate(Editor *ed, void *data, size_t pos, iterator_callback_t call } } +/* A delete operation can either start/stop midway through a piece or at + * a boundry. In the former case a new piece is created to represent the + * remaining text before/after the modification point. + * + * /-+ --> +---------+ --> +-----+ --> +-----+ --> +-\ + * | | | existing| |demo | |text | | | + * \-+ <-- +---------+ <-- +-----+ <-- +-----+ <-- +-/ + * ^ ^ + * |------ delete range -----| + * + * /-+ --> +----+ --> +--+ --> +-\ + * | | | exi| |t | | | + * \-+ <-- +----+ <-- +--+ <-- +-/ + */ bool editor_delete(Editor *ed, size_t pos, size_t len) { if (len == 0) return true; @@ -562,7 +577,7 @@ bool editor_delete(Editor *ed, size_t pos, size_t len) { } if (midway_start) { - /* we finally now which piece follows our newly allocated before piece */ + /* we finally know which piece follows our newly allocated before piece */ piece_init(before, start->prev, after, start->content, off); } -- cgit v1.2.3