From 847178be96f11d555d4ef05641382b5a97367f88 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 18 Mar 2018 15:04:06 +0100 Subject: Create a run when placing cursor in an empty paragraph --- src/sc_parse.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/sc_parse.c') diff --git a/src/sc_parse.c b/src/sc_parse.c index f4717f1..5a653cf 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -87,6 +87,43 @@ const char *sc_block_contents(const SCBlock *bl) } +static SCBlock *sc_find_previous(SCBlock *top, SCBlock *find) +{ + if ( top->next == find ) return top; + + if ( top->child != NULL ) { + SCBlock *t = sc_find_previous(top->child, find); + if ( t != NULL ) return t; + } + if ( top->next != NULL ) { + SCBlock *t = sc_find_previous(top->next, find); + if ( t != NULL ) return t; + } + return NULL; +} + + +/* Add a new block before "bl" */ +SCBlock *sc_block_prepend(SCBlock *bl, SCBlock *top) +{ + SCBlock *bln; + SCBlock *prev; + + prev = sc_find_previous(top, bl); + if ( prev == NULL ) { + fprintf(stderr, "Couldn't find previous\n"); + return NULL; + } + + bln = sc_block_new(); + if ( bln == NULL ) return NULL; + + prev->next = bln; + bln->next = bl; + return bln; +} + + /* Append "bln" after "bl" */ void sc_block_append_p(SCBlock *bl, SCBlock *bln) { -- cgit v1.2.3