vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit fecca123fa0da895aaf93807556db97661fe733d parent 6f509c21437d5d94cbeeba255985b4a49b9cf3f6 Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 17 Jul 2014 22:46:58 +0200 Add some ascii art to illustrate insertion Diffstat:
| M | editor.c | | | 28 | ++++++++++++++++++++++++++++ |
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/editor.c b/editor.c @@ -305,6 +305,34 @@ static Piece* editor_insert_empty(Editor *ed, char *content, size_t len) { return p; } +/* When inserting new data there are 2 cases to consider. + * + * - in the first the insertion point falls into the middle of an exisiting + * piece which is replaced by three new pieces: + * + * /-+ --> +---------------+ --> +-\ + * | | | existing text | | | + * \-+ <-- +---------------+ <-- +-/ + * ^ + * Insertion point for "demo " + * + * /-+ --> +---------+ --> +-----+ --> +-----+ --> +-\ + * | | | existing| |demo | |text | | | + * \-+ <-- +---------+ <-- +-----+ <-- +-----+ <-- +-/ + * + * - the second case deals with an insertion point at a piece boundry: + * + * /-+ --> +---------------+ --> +-\ + * | | | existing text | | | + * \-+ <-- +---------------+ <-- +-/ + * ^ + * Insertion point for "short" + * + * /-+ --> +-----+ --> +---------------+ --> +-\ + * | | |short| | existing text | | | + * \-+ <-- +-----+ <-- +---------------+ <-- +-/ + */ + bool editor_insert(Editor *ed, size_t pos, char *text) { Change *c = change_alloc(ed); if (!c)