Better comments, again (again)

This commit is contained in:
Heath Mitchell 2023-01-29 14:36:12 +00:00
parent af6f449b19
commit 15f038aa85
1 changed files with 26 additions and 8 deletions

View File

@ -20,9 +20,12 @@
enum cursorMoveResult TeX_node_cursor_action(struct TeX_Node *node, struct editContext * context, enum cursorAction action)
{
// Text
// TODO: Store the length of the text in the node
// THat way we won't have to call strlen every time
if (node->type == 0)
{
// Text
// If this isn't where the cursor is, continue the recursive search
if (!context->elementIsText || context->cursorText != node)
return CURSOR_NOT_HERE;
@ -34,7 +37,14 @@ enum cursorMoveResult TeX_node_cursor_action(struct TeX_Node *node, struct editC
context->offset--;
return SUCCESS;
}
if (action == CURSOR_MOVE_RIGHT) {
else if (action == CURSOR_MOVE_RIGHT) {
// We take away 2 because offset 0 is actually one character into the text,
// and the last possible offset is one character before the end of the text,
// because if the cursor is at the start or end it goes in the parent flow.
// TODO: It would make more sense to still have offset 0 be the first character,
// but just make sure that offset is never actually set to 0 before the cursor
// returns to the parent flow.
if (context->offset >= strlen(node->text) - 2)
return CURSOR_PAST_END;
@ -42,35 +52,43 @@ enum cursorMoveResult TeX_node_cursor_action(struct TeX_Node *node, struct editC
return SUCCESS;
}
}
if (node->type > 1)
// Regular nodes
else if (node->type > 1)
{
// If this isn't where the cursor is, continue the recursive search
if (node->args[0] == NULL)
return CURSOR_NOT_HERE;
// Propagate the cursor action to the first child flow
int returnCode = TeX_flow_cursor_action(node->args[0], context, action);
if (returnCode == SUCCESS)
return returnCode;
if (returnCode == CURSOR_PAST_END)
else if (returnCode == CURSOR_PAST_END)
{
// Go to the denominator
// If it moved past the end of the first child, move to the second child
// If there is no second child, leave the node
if (node->args[1] == NULL)
return CURSOR_PAST_END;
// Update the cursor to be in the right place
context->elementIsText = false;
context->cursorFlow = node->args[1];
context->offset = 0;
return SUCCESS;
}
if (returnCode != CURSOR_NOT_HERE)
else if (returnCode != CURSOR_NOT_HERE)
return returnCode;
if (node->args[1] == NULL)
return CURSOR_NOT_HERE;
// Propagate the cursor action to the second child flow
returnCode = TeX_flow_cursor_action(node->args[1], context, action);
if (returnCode == CURSOR_PAST_START)
{
// Go to the numerator
// If it moved past the start of the second child, move to the first child
// The first child should always exist if the second child exists so we don't need to check
context->elementIsText = false;
context->cursorFlow = node->args[0];
context->offset = node->args[0]->elements;