diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-28 11:11:07 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-28 11:11:07 +0200 |
| commit | ddf8647a5393e049f514a39764aebd8893ce00b9 (patch) | |
| tree | 0539941bd5ce776f89af000e8579ae833b90f8c5 /text.c | |
| parent | d954d51a4ce4d6fa13e9312fb72afa0f666a3378 (diff) | |
| download | vis-ddf8647a5393e049f514a39764aebd8893ce00b9.tar.gz vis-ddf8647a5393e049f514a39764aebd8893ce00b9.tar.xz | |
Make '.' repeat last insertion
Diffstat (limited to 'text.c')
| -rw-r--r-- | text.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -110,6 +110,7 @@ struct Text { Buffer *buffers; /* all buffers which have been allocated to hold insertion data */ Piece *pieces; /* all pieces which have been allocated, used to free them */ Piece *cache; /* most recently modified piece */ + Piece *last_insertion; /* most recently inserted piece */ int piece_count; /* number of pieces allocated, only used for debuging purposes */ Piece begin, end; /* sentinel nodes which always exists but don't hold any data */ Action *redo, *undo; /* two stacks holding all actions performed to the file */ @@ -395,6 +396,8 @@ static void piece_free(Piece *p) { p->text->pieces = p->global_next; if (p->text->cache == p) p->text->cache = NULL; + if (p->text->last_insertion == p) + p->text->last_insertion = NULL; free(p); } @@ -555,6 +558,7 @@ bool text_insert(Text *txt, size_t pos, const char *data, size_t len) { span_init(&c->old, p, p); } + txt->last_insertion = new; cache_piece(txt, new); span_swap(txt, &c->old, &c->new); return true; @@ -802,6 +806,15 @@ void text_snapshot(Text *txt) { txt->cache = NULL; } +size_t text_last_insertion(Text *txt, const char **content) { + if (!txt->last_insertion) { + *content = NULL; + return 0; + } + *content = txt->last_insertion->data; + return txt->last_insertion->len; +} + void text_free(Text *txt) { if (!txt) return; |
