From d5e66208ef33a792498f6765008656fe90caae68 Mon Sep 17 00:00:00 2001 From: Denis Lantsman Date: Sat, 14 Dec 2024 12:38:35 -0800 Subject: [PATCH] fixup some edge cases --- rplugin/node/magenta/src/chat/message.ts | 2 +- rplugin/node/magenta/src/tea/update.ts | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/rplugin/node/magenta/src/chat/message.ts b/rplugin/node/magenta/src/chat/message.ts index f0fa068..78763e4 100644 --- a/rplugin/node/magenta/src/chat/message.ts +++ b/rplugin/node/magenta/src/chat/message.ts @@ -67,7 +67,7 @@ export const update: Update = (msg, model) => { export const view: View<{ model: Model; dispatch: Dispatch }> = ({ model, -}) => d`\ +}) => d` ### ${model.role}: ${model.parts.map((part) => partView({ model: part }))}`; diff --git a/rplugin/node/magenta/src/tea/update.ts b/rplugin/node/magenta/src/tea/update.ts index e9c8349..189e723 100644 --- a/rplugin/node/magenta/src/tea/update.ts +++ b/rplugin/node/magenta/src/tea/update.ts @@ -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 { @@ -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( @@ -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: [], }); @@ -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; }