]> git.mdlowis.com Git - projs/tide.git/commitdiff
commented edit log additions
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 18 Oct 2019 03:30:31 +0000 (23:30 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 18 Oct 2019 03:30:31 +0000 (23:30 -0400)
src/lib/editlog.c

index ae1467d41042676e820246184eb2bc37983f8dfa..ee2ce382d3218f5751e70cfd7fc27c8b58e0b68e 100644 (file)
@@ -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);