From 01cb37c269da731a2f27bf9dd47b347726f63190 Mon Sep 17 00:00:00 2001 From: Rick Hennigan Date: Thu, 25 Jan 2024 13:46:36 -0500 Subject: [PATCH] If the existing chat output has been removed before a new paged output can be created, just create a new chat output --- Source/Chatbook/SendChat.wl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/Chatbook/SendChat.wl b/Source/Chatbook/SendChat.wl index 382b691e..16385f40 100644 --- a/Source/Chatbook/SendChat.wl +++ b/Source/Chatbook/SendChat.wl @@ -1654,9 +1654,14 @@ createNewChatOutput // endDefinition; prepareChatOutputPage // beginDefinition; prepareChatOutputPage[ target_CellObject, cell_Cell ] := Enclose[ - Module[ { prevCellExpr, prevPage, encoded, pageData, newCellObject }, + Catch @ Module[ { prevCellExpr, prevPage, encoded, pageData, newCellObject }, - prevCellExpr = ConfirmMatch[ NotebookRead @ target, _Cell, "NotebookRead" ]; + prevCellExpr = ConfirmMatch[ NotebookRead @ target, _Cell | $Failed, "NotebookRead" ]; + + If[ FailureQ @ prevCellExpr, + (* The target cell is gone, so just create a new one instead of trying to page outputs: *) + Throw @ cellPrint @ cell + ]; prevPage = ConfirmMatch[ Replace[ First @ prevCellExpr, text_String :> TextData @ { text } ], @@ -1691,7 +1696,7 @@ prepareChatOutputPage[ target_CellObject, cell_Cell ] := Enclose[ CurrentValue[ newCellObject, { TaggingRules, "PageData" } ] = pageData; newCellObject ], - throwInternalFailure[ prepareChatOutputPage[ target, cell ], ## ] & + throwInternalFailure ]; prepareChatOutputPage // endDefinition;