Skip to content

Commit

Permalink
If the existing chat output has been removed before a new paged outpu…
Browse files Browse the repository at this point in the history
…t can be created, just create a new chat output
  • Loading branch information
rhennigan committed Jan 25, 2024
1 parent 087f467 commit 01cb37c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Source/Chatbook/SendChat.wl
Original file line number Diff line number Diff line change
Expand Up @@ -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 } ],
Expand Down Expand Up @@ -1691,7 +1696,7 @@ prepareChatOutputPage[ target_CellObject, cell_Cell ] := Enclose[
CurrentValue[ newCellObject, { TaggingRules, "PageData" } ] = pageData;
newCellObject
],
throwInternalFailure[ prepareChatOutputPage[ target, cell ], ## ] &
throwInternalFailure
];

prepareChatOutputPage // endDefinition;
Expand Down

0 comments on commit 01cb37c

Please sign in to comment.