aboutsummaryrefslogtreecommitdiff
path: root/src/sc_parse.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2018-03-18 15:04:06 +0100
committerThomas White <taw@physics.org>2018-03-18 23:14:13 +0100
commit847178be96f11d555d4ef05641382b5a97367f88 (patch)
treea7878b36d81a7283d1ad1e27c6a47fbe0bebf444 /src/sc_parse.c
parent546bfb401b943b0b5e91f3674c450c4a78aeb6aa (diff)
Create a run when placing cursor in an empty paragraph
Diffstat (limited to 'src/sc_parse.c')
-rw-r--r--src/sc_parse.c37
1 files changed, 37 insertions, 0 deletions
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)
{