Skip to content

Commit

Permalink
Merge pull request #505 from WolframResearch/350-executing-a-chatexcl…
Browse files Browse the repository at this point in the history
…uded-chatinput-cell-generates-a-failure

Bugfix: Return `Null` instead of generating an internal failure if the current chat input is excluded
  • Loading branch information
rhennigan authored Jan 2, 2024
2 parents 3f9852d + feaac5b commit 56fd8b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
7 changes: 5 additions & 2 deletions Source/Chatbook/Actions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,10 @@ EvaluateChatInput // beginDefinition;
EvaluateChatInput[ ] := EvaluateChatInput @ rootEvaluationCell[ ];

EvaluateChatInput[ evalCell_CellObject? chatInputCellQ ] :=
EvaluateChatInput[ evalCell, parentNotebook @ evalCell ];
If[ chatExcludedQ @ evalCell,
Null,
EvaluateChatInput[ evalCell, parentNotebook @ evalCell ]
];

EvaluateChatInput[ source: _CellObject | $Failed ] :=
With[ { evalCell = rootEvaluationCell @ source },
Expand Down Expand Up @@ -1034,7 +1037,7 @@ SendChat // beginDefinition;

SendChat[ ] := SendChat @ rootEvaluationCell[ ];

SendChat[ evalCell_CellObject, ___ ] /; MemberQ[ CurrentValue[ evalCell, CellStyle ], "ChatExcluded" ] := Null;
SendChat[ evalCell_CellObject? chatExcludedQ, ___ ] := Null;

SendChat[ evalCell_CellObject ] := SendChat[ evalCell, parentNotebook @ evalCell ];

Expand Down
30 changes: 17 additions & 13 deletions Source/Chatbook/ChatHistory.wl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ BeginPackage[ "Wolfram`Chatbook`ChatHistory`" ];

HoldComplete[
`accentIncludedCells;
`chatExcludedQ;
`extraCellHeight;
`filterChatCells;
`getCellsInChatHistory;
Expand Down Expand Up @@ -172,24 +173,27 @@ selectChatHistoryCells // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*filterChatCells*)
filterChatCells // beginDefinition;
(*chatExcludedQ*)
chatExcludedQ // beginDefinition;

filterChatCells[ cellInfo: { ___Association } ] := Enclose[
Module[ { styleExcluded, tagExcluded, cells },
chatExcludedQ[ cell_CellObject ] := chatExcludedQ @ cellInformation @ cell;

styleExcluded = DeleteCases[ cellInfo, KeyValuePattern[ "Style" -> $$chatIgnoredStyle ] ];
chatExcludedQ[ Cell[ __, $$chatIgnoredStyle, ___ ] ] := True;
chatExcludedQ[ Cell[ __, TaggingRules -> tags_, ___ ] ] := chatExcludedQ @ tags;
chatExcludedQ[ Cell[ ___ ] ] := False;

tagExcluded = DeleteCases[
styleExcluded,
KeyValuePattern[ "ChatNotebookSettings" -> KeyValuePattern[ "ExcludeFromChat" -> True ] ]
];
chatExcludedQ[ KeyValuePattern[ "Style" -> $$chatIgnoredStyle ] ] := True;
chatExcludedQ[ KeyValuePattern[ "ChatNotebookSettings" -> settings_ ] ] := chatExcludedQ @ settings;
chatExcludedQ[ KeyValuePattern[ "ExcludeFromChat" -> exclude_ ] ] := TrueQ @ exclude;
chatExcludedQ[ KeyValuePattern[ { } ] ] := False;

tagExcluded
],
throwInternalFailure[ filterChatCells @ cellInfo, ## ] &
];
chatExcludedQ // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*filterChatCells*)
filterChatCells // beginDefinition;
filterChatCells[ cellInfo: { ___Association } ] := Select[ cellInfo, Not @* chatExcludedQ ];
filterChatCells // endDefinition;

(* ::**************************************************************************************************************:: *)
Expand Down
3 changes: 3 additions & 0 deletions Source/Chatbook/SendChat.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,9 @@ selectChatCells0[ cell_, cells: { __CellObject }, final_ ] := Enclose[
(* Filter out ignored cells *)
filtered = ConfirmMatch[ filterChatCells @ selectedRange, { ___Association }, "FilteredCellInfo" ];

(* If all cells are excluded, do nothing *)
If[ filtered === { }, throwTop @ Null ];

(* Delete output cells that come after the evaluation cell *)
rest = deleteExistingChatOutputs @ Drop[ cellData, cellPosition ];

Expand Down

0 comments on commit 56fd8b3

Please sign in to comment.