From a22e1a5b7a68ea19012c09e961f1bb4c86f4107b Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 25 Oct 2019 23:39:18 -0400 Subject: [PATCH] refactored undo/redo log api --- inc/edit.h | 8 ++++---- src/lib/buf.c | 8 ++++---- src/lib/editlog.c | 28 ++++++++++++++-------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index c9529e9..41d1447 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -56,10 +56,10 @@ char gapbuf_getb(GapBuf* buf, size_t off); void gapbuf_putb(GapBuf* buf, char b, Sel* p_sel); void gapbuf_del(GapBuf* buf, size_t off, size_t len); -void editlog_seqstart(Buf* log); -void editlog_seqstop(Buf* log); -void editlog_clear(Buf* log); -void editlog_lastins(Buf* buf, Sel* p_sel); +void editlog_seqstart(EditLog* log); +void editlog_seqstop(EditLog* log); +void editlog_clear(EditLog* log); +void editlog_lastins(EditLog* log, Sel* p_sel); void editlog_undo(Buf* log); void editlog_redo(Buf* log); void editlog_add(Buf* buf, size_t beg, size_t end, char* data); diff --git a/src/lib/buf.c b/src/lib/buf.c index 08b84ff..055adb8 100644 --- a/src/lib/buf.c +++ b/src/lib/buf.c @@ -234,22 +234,22 @@ int buf_save(Buf* buf, char* path) ******************************************************************************/ void buf_logstart(Buf* buf) { - editlog_seqstart(buf); + editlog_seqstart(&(buf->log)); } void buf_logstop(Buf* buf) { - editlog_seqstop(buf); + editlog_seqstop(&(buf->log)); } void buf_logclear(Buf* buf) { - editlog_clear(buf); + editlog_clear(&(buf->log)); } void buf_lastins(Buf* buf) { - editlog_lastins(buf, &(buf->selection)); + editlog_lastins(&(buf->log), &(buf->selection)); } void buf_undo(Buf* buf) diff --git a/src/lib/editlog.c b/src/lib/editlog.c index d570343..c7a28d7 100644 --- a/src/lib/editlog.c +++ b/src/lib/editlog.c @@ -78,32 +78,32 @@ static void log_clear(Log** list) } } -void editlog_seqstart(Buf* buf) +void editlog_seqstart(EditLog* log) { - require(buf != NULL); - buf->log.transid = abs(buf->log.transid); + require(log != NULL); + log->transid = abs(log->transid); } -void editlog_seqstop(Buf* buf) +void editlog_seqstop(EditLog* log) { - require(buf != NULL); - if (buf->log.transid > 0) + require(log != NULL); + if (log->transid > 0) { - buf->log.transid = -(buf->log.transid + 1); + log->transid = -(log->transid + 1); } } -void editlog_clear(Buf* buf) +void editlog_clear(EditLog* log) { - require(buf != NULL); - log_clear(&(buf->log.redo)); - log_clear(&(buf->log.undo)); + require(log != NULL); + log_clear(&(log->redo)); + log_clear(&(log->undo)); } -void editlog_lastins(Buf* buf, Sel* p_sel) +void editlog_lastins(EditLog* elog, Sel* p_sel) { - require(buf != NULL); - Log* log = buf->log.undo; + require(elog != NULL); + Log* log = elog->undo; if (log) { Sel sel = { .beg = log->beg, .end = log->end }; -- 2.52.0