aboutsummaryrefslogtreecommitdiff
path: root/editor.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-07-21 13:22:56 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-07-21 13:22:56 +0200
commit67d8948f37e59b9206e27070d91c7e368c099aae (patch)
tree9e7ea6065e844561acb108ea985993c26ac6dbc4 /editor.c
parent843d628895c31eacd2aa89d44c1a4535dd601215 (diff)
downloadvis-67d8948f37e59b9206e27070d91c7e368c099aae.tar.gz
vis-67d8948f37e59b9206e27070d91c7e368c099aae.tar.xz
Add comments regarding deletion
Diffstat (limited to 'editor.c')
-rw-r--r--editor.c17
1 files changed, 16 insertions, 1 deletions
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);
}