Skip to content

Commit

Permalink
fixup some edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dlants committed Dec 14, 2024
1 parent be7fbc7 commit d5e6620
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rplugin/node/magenta/src/chat/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const update: Update<Msg, Model> = (msg, model) => {

export const view: View<{ model: Model; dispatch: Dispatch<Msg> }> = ({
model,
}) => d`\
}) => d`
### ${model.role}:
${model.parts.map((part) => partView({ model: part }))}`;
17 changes: 10 additions & 7 deletions rplugin/node/magenta/src/tea/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ export async function update({
...current,
children: nextChildren,
startPos,
endPos: nextChildren[nextChildren.length - 1].endPos,
endPos: nextChildren.length
? nextChildren[nextChildren.length - 1].endPos
: updatePos(current.endPos),
};
return nextMountedNode;
} else {
Expand All @@ -179,6 +181,9 @@ export async function update({
const nextChild = nextNode.children[i];
nextChildren.push(await visitNode(currentChild, nextChild));
}
let endPos = nextChildren.length
? nextChildren[nextChildren.length - 1].endPos
: updatePos(current.endPos);

if (current.children.length > nextNode.children.length) {
const oldChildrenEndPos = updatePos(
Expand All @@ -187,7 +192,7 @@ export async function update({
// remove all the nodes between the end of the last child and where the remaining children would go.
await replaceBetweenPositions({
...mount,
startPos: nextChildren[nextChildren.length - 1].endPos,
startPos: endPos,
endPos: oldChildrenEndPos,
lines: [],
});
Expand All @@ -201,19 +206,17 @@ export async function update({
childIdx += 1
) {
nextChildren.push(
await insertNode(
nextNode.children[childIdx],
nextChildren[nextChildren.length - 1].endPos,
),
await insertNode(nextNode.children[childIdx], endPos),
);
}
endPos = nextChildren[nextChildren.length - 1].endPos;
}

const nextMountedNode = {
...current,
children: nextChildren,
startPos,
endPos: nextChildren[nextChildren.length - 1].endPos,
endPos,
};
return nextMountedNode;
}
Expand Down

0 comments on commit d5e6620

Please sign in to comment.