From: Michael D. Lowis Date: Fri, 18 Oct 2019 03:30:31 +0000 (-0400) Subject: commented edit log additions X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4d30eed8f3cffa420d9c1c1a4f49241e513cd694;p=projs%2Ftide.git commented edit log additions --- diff --git a/src/lib/editlog.c b/src/lib/editlog.c index ae1467d..ee2ce38 100644 --- a/src/lib/editlog.c +++ b/src/lib/editlog.c @@ -157,15 +157,17 @@ void editlog_add(Buf* buf, size_t beg, size_t end, char* data) Log* prev = buf->undo; log_clear(&(buf->redo)); - /* decide if this is an insert or delete */ + /* check if this is new transaction or the first entry */ if (!prev || (buf->transid > 0 && buf->transid != prev->transid)) { buf->undo = mklog(buf, beg, end, data, prev); } + /* check if this is a sequential insert, just expand the previous one */ else if (!data && !prev->data && prev->end == beg) { prev->end = end; } + /* check if this is a sequential delete, append to deleted text */ else if (prev->data && data && prev->beg == beg) { char* newdata = strmcat(prev->data, data, 0); @@ -173,6 +175,7 @@ void editlog_add(Buf* buf, size_t beg, size_t end, char* data) free(prev->data); prev->data = newdata; } + /* check if this is a delete before the previous operation, prepend to deleted text */ else if (prev->data && data && prev->beg == beg+1) { char* newdata = strmcat(data, prev->data, 0); @@ -181,6 +184,7 @@ void editlog_add(Buf* buf, size_t beg, size_t end, char* data) prev->data = newdata; prev->end = --prev->beg; } + /* otherwise, make a fresh delete operation */ else { buf->undo = mklog(buf, beg, end, data, prev);