From af6f449b1987594233660e9eac339cd0f249a8ca Mon Sep 17 00:00:00 2001 From: Heath123 Date: Sun, 29 Jan 2023 14:21:16 +0000 Subject: [PATCH] Better comments, again --- src/node.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/node.c b/src/node.c index f1d3903..42207d4 100644 --- a/src/node.c +++ b/src/node.c @@ -86,24 +86,28 @@ enum cursorMoveResult TeX_node_cursor_enter(struct TeX_Node *node, struct editCo { enum cursorMoveResult skipPast = action == CURSOR_MOVE_RIGHT ? CURSOR_PAST_END : CURSOR_PAST_START; + // Text if (node->type == 0) { int len = strlen(node->text); if (len == 1) return skipPast; - // Text context->elementIsText = true; context->cursorText = node; context->offset = action == CURSOR_MOVE_RIGHT ? 0 : len - 2; return SUCCESS; } - if (node->type > 1) + // Regular nodes + else if (node->type > 1) { if (action == CURSOR_MOVE_RIGHT) { - // Enter the numerator + // Enter the first child flow + + // If there is no child, skip past this node if (node->args[0] == NULL) return CURSOR_PAST_END; + // Update the cursor to be in the right place context->elementIsText = false; context->cursorFlow = node->args[0]; context->offset = 0; @@ -111,14 +115,19 @@ enum cursorMoveResult TeX_node_cursor_enter(struct TeX_Node *node, struct editCo } else if (action == CURSOR_MOVE_LEFT) { - // Enter the denominator + // Enter the last child flow + struct TeX_Flow *denom = node->args[1]; + + // If there is only one child, go to it instead if (denom == NULL) denom = node->args[0]; + // If there is no child, skip past this node if (denom == NULL) return CURSOR_PAST_START; + // Update the cursor to be in the right place context->elementIsText = false; context->cursorFlow = denom; context->offset = denom->elements;