Skip to content

Commit 84eee70

Browse files
authored
Merge pull request #1361 from WolframResearch/bugfix/Sidebar4
Bugfix/sidebar4
2 parents 14e27d9 + 7c93a8f commit 84eee70

File tree

8 files changed

+43
-171
lines changed

8 files changed

+43
-171
lines changed

DarkModeSupport/TextResources/ChatbookResources.tr

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9841,15 +9841,16 @@ VX/aMEEQzrerjFhhelYAzofFB3r8AgApYdcE
98419841
FrameMargins->0,
98429842
ImageSize->Automatic],
98439843

9844-
"NotebookAssistantSidebarCell" -> Cell[BoxData[{
9845-
DynamicBox[ToBoxes[Needs["Wolfram`Chatbook`" -> None]; RawBoxes[
9846-
Symbol["Wolfram`Chatbook`ChatbookAction"]["MakeSidebarChatDockedCell"]],
9847-
StandardForm],
9848-
DestroyAfterEvaluation->True], "\n",
9849-
DynamicBox[ToBoxes[Needs["Wolfram`Chatbook`" -> None]; RawBoxes[
9850-
Symbol["Wolfram`Chatbook`ChatModes`Common`sidebarChatInputCell"][]],
9851-
StandardForm],
9852-
DestroyAfterEvaluation->True]}],
9844+
"NotebookAssistantSidebarCell" -> Cell[BoxData[
9845+
RowBox[{
9846+
DynamicBox[ToBoxes[Needs["Wolfram`Chatbook`" -> None]; RawBoxes[
9847+
Symbol["Wolfram`Chatbook`ChatbookAction"]["MakeSidebarChatDockedCell"]],
9848+
StandardForm],
9849+
DestroyAfterEvaluation->True],
9850+
DynamicBox[ToBoxes[Needs["Wolfram`Chatbook`" -> None]; RawBoxes[
9851+
Symbol["Wolfram`Chatbook`ChatModes`Common`sidebarChatInputCell"][]],
9852+
StandardForm],
9853+
DestroyAfterEvaluation->True]}]],
98539854
Editable->True,
98549855
Selectable->False,
98559856
CellMargins->{{0, 0}, {0, 0}},
@@ -9872,8 +9873,8 @@ notebookAssistanceSidebarSettings, "ConversationTitle" -> ""|>),
98729873
GrayLevel[0.95],
98739874
RGBColor[0.1882352, 0.2078431, 0.2274509]],
98749875
CellTags->
9875-
"NotebookAssistantSidebarCell",ExpressionUUID->"6696f587-5fe9-ad4b-a610-\
9876-
df2378d4af41"],
9876+
"NotebookAssistantSidebarCell",ExpressionUUID->"63d02243-e7fb-e74f-b904-\
9877+
32a950285a1a"],
98779878

98789879
"SidebarIconHide" -> (GraphicsBox[{
98799880
Thickness[0.125],

Developer/Resources/FrontEndResources/SideBarChat/NotebookAssistantSideBarCell.wl renamed to Developer/Resources/FrontEndResources/SideBarChat/NotebookAssistantSidebarCell.wl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Cell[
99
StandardForm ],
1010
DestroyAfterEvaluation -> True
1111
],
12-
"\n",
1312
DynamicBox[
1413
ToBoxes[
1514
Needs[ "Wolfram`Chatbook`" -> None ];

Source/Chatbook/Actions.wl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,13 @@ regenerateAssistantMessage[ chatOutput_CellObject, True(*sidebarCellQ_*) ] := En
117117
chatInputFieldCell = ConfirmMatch[ Last[ Cells[ sidebarCell, CellTags -> "SidebarChatInputCell" ], None ], _CellObject, "SidebarChatInputFieldCell" ];
118118

119119
With[ { sbc = sidebarCell, cic = chatInputCell }, (* "Set" is HoldFirst so we must inject values *)
120-
WithCleanup[
121-
FrontEndExecute[ {
122-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
123-
FrontEnd`SelectionMove[ chatOutput, Before, Cell ],
124-
FrontEnd`FrontEndToken[ nbo, "DeletePrevious" ], (* remove the newline character before the sub-cell *)
125-
FrontEnd`NotebookDelete @ chatOutput,
126-
FrontEnd`SetValue @ FEPrivate`Set[ FrontEnd`CurrentValue[ sbc, { TaggingRules, "ChatEvaluationCell" } ], cic ], (* use TaggingRules to pass CellObject around *)
127-
FrontEnd`SetOptions[ chatInputFieldCell, CellTags -> { "SidebarChatInputCell", "RegenerateChatOutput" } ] (* backdoor to re-evaluation in side bar *)
128-
} ]
129-
,
130-
CurrentValue[ sidebarCell, Editable ] = Inherited
131-
]
120+
FrontEndExecute[ {
121+
FrontEnd`SelectionMove[ chatOutput, Before, Cell ],
122+
FrontEnd`FrontEndToken[ nbo, "DeletePrevious" ], (* remove the newline character before the sub-cell *)
123+
FrontEnd`NotebookDelete @ chatOutput,
124+
FrontEnd`SetValue @ FEPrivate`Set[ FrontEnd`CurrentValue[ sbc, { TaggingRules, "ChatEvaluationCell" } ], cic ], (* use TaggingRules to pass CellObject around *)
125+
FrontEnd`SetOptions[ chatInputFieldCell, CellTags -> { "SidebarChatInputCell", "RegenerateChatOutput" } ] (* backdoor to re-evaluation in side bar *)
126+
} ]
132127
];
133128
],
134129
throwInternalFailure

Source/Chatbook/ChatModes/Evaluate.wl

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,12 @@ evaluateSidebarChat[ nbo_NotebookObject, sidebarCell_CellObject, input_, Dynamic
8282
scrollablePaneCell = First[ Cells[ sidebarCell, CellTags -> "SidebarScrollingContentCell" ], Missing @ "NoScrollingContent" ];
8383
If[ MissingQ @ scrollablePaneCell,
8484
lastDockedCell = ConfirmMatch[ Last[ Cells[ sidebarCell, CellTags -> "SidebarDockedCell" ], $Failed ], _CellObject, "SidebarDockedCell" ];
85-
WithCleanup[
86-
FrontEndExecute[ {
87-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
88-
FrontEnd`SelectionMove[ lastDockedCell, After, Cell, AutoScroll -> True ],
89-
FrontEnd`NotebookWrite[ nbo, RowBox[ { "\n", sidebarScrollingCell[ nbo, { cell } ] } ] ] } ]
90-
,
91-
CurrentValue[ sidebarCell, Editable ] = Inherited
92-
];
85+
NotebookWrite[ System`NotebookLocationSpecifier[ lastDockedCell, "After" ], sidebarScrollingCell[ nbo, { cell } ] ];
9386
scrollablePaneCell = ConfirmMatch[ First[ Cells[ sidebarCell, CellTags -> "SidebarScrollingContentCell" ], $Failed ], _CellObject, "UpdatedSidebarScrollableCell" ];
9487
, (* ELSE *)
9588
(* The scrolling pane cell should only exist if it contains content. If it exists without content then something has gone wrong. *)
9689
lastContentCell = ConfirmMatch[ Last[ Cells[ scrollablePaneCell, CellTags -> "SidebarTopCell" ], $Failed ], _CellObject, "NoSidebarScrollingContentCell" ];
97-
WithCleanup[
98-
FrontEndExecute[ {
99-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
100-
FrontEnd`SelectionMove[ lastContentCell, After, Cell, AutoScroll -> True ],
101-
FrontEnd`NotebookWrite[ nbo, RowBox[ { "\n", cell } ] ] } ]
102-
,
103-
CurrentValue[ sidebarCell, Editable ] = Inherited
104-
]
90+
NotebookWrite[ System`NotebookLocationSpecifier[ lastContentCell, "After" ], cell ]
10591
];
10692

10793
cellObject = ConfirmMatch[ Last[ Cells[ scrollablePaneCell, CellTags -> uuid ], $Failed ], _CellObject, "SidebarChatInputCellObject" ];

Source/Chatbook/ChatModes/ShowNotebookAssistance.wl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ $notebookAssistanceMenuItems = <|
123123
FrontEndResource[ "ChatbookStrings", "MenuItemShowNotebookAssistanceWindow" ],
124124
FrontEnd`KernelExecute[
125125
Needs[ "Wolfram`Chatbook`" -> None ];
126-
Symbol[ "Wolfram`Chatbook`ShowNotebookAssistance" ][ "Window", "NewChat" -> True ]
126+
Symbol[ "Wolfram`Chatbook`ShowNotebookAssistance" ][ If[ BoxForm`sufficientVersionQ[ 15.0 ], "Sidebar", "Window" ], "NewChat" -> True ]
127127
],
128128
FrontEnd`MenuEvaluator -> Automatic,
129129
Evaluate[

Source/Chatbook/ChatModes/UI.wl

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,11 @@ writeSidebarChatSubDockedCell[ nbo_NotebookObject, sidebarCell_CellObject, conte
118118
subDockedCell = First[ Cells[ sidebarCell, CellTags -> "SidebarSubDockedCell" ], $Failed ];
119119
If[ ! FailureQ @ subDockedCell,
120120
(* if the sub-cell already exists then rewrite it *)
121-
WithCleanup[
122-
FrontEndExecute[ {
123-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
124-
FrontEnd`NotebookWrite[ subDockedCell, makeSidebarChatSubDockedCellExpression[ nbo, sidebarCell, content ] ]
125-
} ]
126-
,
127-
CurrentValue[ sidebarCell, Editable ] = Inherited
128-
]
121+
NotebookWrite[ subDockedCell, makeSidebarChatSubDockedCellExpression[ nbo, sidebarCell, content ] ]
129122
,
130123
(* else, write a new sub-cell after the last docked cell *)
131124
lastDockedCell = ConfirmMatch[ Last[ Cells[ sidebarCell, CellTags -> "SidebarDockedCell" ], $Failed ], _CellObject, "SidebarDockedCell" ];
132-
WithCleanup[
133-
FrontEndExecute[ {
134-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
135-
FrontEnd`SelectionMove[ lastDockedCell, After, Cell ],
136-
FrontEnd`NotebookWrite[ nbo, RowBox[ { "\n", makeSidebarChatSubDockedCellExpression[ nbo, sidebarCell, content ] } ] ]
137-
} ]
138-
,
139-
CurrentValue[ sidebarCell, Editable ] = Inherited
140-
]
125+
NotebookWrite[ System`NotebookLocationSpecifier[ lastDockedCell, "After" ], makeSidebarChatSubDockedCellExpression[ nbo, sidebarCell, content ] ]
141126
];
142127
(* TODO: move selection to side bar chat's input field *)
143128
],
@@ -167,17 +152,7 @@ removeSidebarChatSubDockedCell // beginDefinition;
167152

168153
removeSidebarChatSubDockedCell[ nbo_NotebookObject, sidebarCell_CellObject ] := Module[ { subDockedCell },
169154
subDockedCell = First[ Cells[ sidebarCell, CellTags -> "SidebarSubDockedCell" ], Missing @ "NoSidebarSubDockedCell" ];
170-
If[ ! MissingQ @ subDockedCell,
171-
WithCleanup[
172-
FrontEndExecute[ {
173-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
174-
FrontEnd`SelectionMove[ subDockedCell, Before, Cell ],
175-
FrontEnd`FrontEndToken[ nbo, "DeletePrevious" ], (* remove the newline character before the sub-cell *)
176-
FrontEnd`NotebookDelete @ subDockedCell } ]
177-
,
178-
CurrentValue[ sidebarCell, Editable ] = Inherited
179-
]
180-
]
155+
If[ ! MissingQ @ subDockedCell, NotebookDelete @ subDockedCell ]
181156
];
182157

183158
removeSidebarChatSubDockedCell // endDefinition;
@@ -187,15 +162,7 @@ removeSidebarChatSubDockedCell // endDefinition;
187162
(*removeSidebarTopCell*)
188163
removeSidebarTopCell // beginDefinition;
189164

190-
removeSidebarTopCell[ nbo_NotebookObject, sidebarTopCell_CellObject ] := WithCleanup[
191-
FrontEndExecute[ {
192-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
193-
FrontEnd`SelectionMove[ sidebarTopCell, Before, Cell ],
194-
FrontEnd`FrontEndToken[ nbo, "DeletePrevious" ], (* remove the newline character before the top cell *)
195-
FrontEnd`NotebookDelete @ sidebarTopCell } ]
196-
,
197-
CurrentValue[ sidebarCell, Editable ] = Inherited
198-
];
165+
removeSidebarTopCell[ nbo_NotebookObject, sidebarTopCell_CellObject ] := NotebookDelete @ sidebarTopCell;
199166

200167
removeSidebarTopCell // endDefinition;
201168

@@ -206,17 +173,7 @@ removeSidebarScrollingContentCell // beginDefinition;
206173

207174
removeSidebarScrollingContentCell[ nbo_NotebookObject, sidebarCell_CellObject ] := Module[ { scrollablePaneCell },
208175
scrollablePaneCell = First[ Cells[ sidebarCell, CellTags -> "SidebarScrollingContentCell" ], Missing @ "NoScrollingSidebarCell" ];
209-
If[ ! MissingQ @ scrollablePaneCell,
210-
WithCleanup[
211-
FrontEndExecute[ {
212-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
213-
FrontEnd`SelectionMove[ scrollablePaneCell, Before, Cell ],
214-
FrontEnd`FrontEndToken[ nbo, "DeletePrevious" ], (* remove the newline character before the top cell *)
215-
FrontEnd`NotebookDelete @ scrollablePaneCell } ]
216-
,
217-
CurrentValue[ sidebarCell, Editable ] = Inherited
218-
]
219-
]
176+
If[ ! MissingQ @ scrollablePaneCell, NotebookDelete @ scrollablePaneCell ]
220177
];
221178

222179
removeSidebarScrollingContentCell // endDefinition;
@@ -234,7 +191,7 @@ Module[ { sidebarCellObj, dockedCellObj, chatInputCellObj },
234191
With[ { sc = sidebarCellObj, cc = chatInputCellObj, dc = dockedCellObj },
235192
Cell[ BoxData @
236193
PaneBox[
237-
RowBox @ Riffle[ cells, "\n" ],
194+
RowBox @ cells,
238195
AppearanceElements -> {},
239196
ImageSize ->
240197
Dynamic[
@@ -2700,25 +2657,9 @@ loadConversation[ nbo_NotebookObject, sidebarCell_CellObject, id_ ] := Enclose[
27002657
scrollablePaneCell = First[ Cells[ sidebarCell, CellTags -> "SidebarScrollingContentCell" ], Missing @ "NoScrollingContent" ];
27012658
If[ MissingQ @ scrollablePaneCell,
27022659
lastDockedCell = ConfirmMatch[ Last[ Cells[ sidebarCell, CellTags -> "SidebarDockedCell" ], $Failed ], _CellObject, "SidebarDockedCell" ];
2703-
(* FIXME: this can write to the notebook content area if its empty *)
2704-
WithCleanup[
2705-
FrontEndExecute[ {
2706-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
2707-
FrontEnd`SelectionMove[ lastDockedCell, After, Cell, AutoScroll -> True ],
2708-
FrontEnd`NotebookWrite[ nbo, RowBox[ { "\n", sidebarScrollingCell[ nbo, cells ] } ] ]
2709-
} ]
2710-
,
2711-
CurrentValue[ sidebarCell, Editable ] = Inherited
2712-
]
2660+
NotebookWrite[ System`NotebookLocationSpecifier[ lastDockedCell, "After" ], sidebarScrollingCell[ nbo, cells ] ]
27132661
, (* ELSE *)
2714-
WithCleanup[
2715-
FrontEndExecute[ {
2716-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
2717-
FrontEnd`NotebookWrite[ scrollablePaneCell, sidebarScrollingCell[ nbo, cells ] ]
2718-
} ]
2719-
,
2720-
CurrentValue[ sidebarCell, Editable ] = Inherited
2721-
]
2662+
NotebookWrite[ scrollablePaneCell, sidebarScrollingCell[ nbo, cells ] ]
27222663
];
27232664

27242665
CurrentChatSettings[ sidebarCell, "ConversationUUID" ] = uuid;

Source/Chatbook/FrontEnd.wl

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -709,21 +709,9 @@ cloudCellPrint // endDefinition;
709709
cellPrintAfter[ target_ ][ cell_ ] := cellPrintAfter[ target, cell ];
710710

711711
cellPrintAfter[ target_CellObject, cell: Cell[ __, ExpressionUUID -> uuid_, ___ ] ] /; cellTaggedQ[ target, "SidebarTopCell" ] := Enclose[
712-
Module[ { sidebarCell },
713-
(* topParentCell is blocked from recursing past a "SidebarTopCell", but we know the parent distance to the side bar cell *)
714-
sidebarCell = ConfirmMatch[ ParentCell @ ParentCell @ target, _CellObject, "SidebarCellPrintAfter" ];
715-
WithCleanup[
716-
FrontEndExecute[ {
717-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
718-
FrontEnd`SelectionMove[ target, After, Cell, AutoScroll -> True ],
719-
FrontEnd`NotebookWrite[ parentNotebook @ target, RowBox[ { "\n", cell } ] ]
720-
} ]
721-
,
722-
CurrentValue[ sidebarCell, Editable ] = Inherited
723-
];
724-
(* this should return the CellObject of the newly written inline cell in the scrolling content cell *)
725-
ConfirmMatch[ NextCell @ target, _CellObject, "SidebarCellPrintAfterCellObject" ]
726-
]
712+
NotebookWrite[ System`NotebookLocationSpecifier[ target, "After" ], cell ];
713+
(* this should return the CellObject of the newly written inline cell in the scrolling content cell *)
714+
ConfirmMatch[ NextCell @ target, _CellObject, "SidebarCellPrintAfterCellObject" ]
727715
,
728716
throwInternalFailure
729717
];

Source/Chatbook/SendChat.wl

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,28 +1429,14 @@ splitDynamicContent[ container_, { static__String, dynamic_String }, cell_CellOb
14291429

14301430
container[ "DynamicContent" ] = dynamic;
14311431

1432-
If[ TrueQ @ $SidebarChat,
1433-
With[ { boxObject = boxObject, write = write, sidebarCell = sidebarCellObject @ nbo },
1434-
splitDynamicTaskFunction @
1435-
WithCleanup[
1436-
FrontEndExecute[ {
1437-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
1438-
FrontEnd`NotebookWrite[ System`NotebookLocationSpecifier[ boxObject, "Before" ], write, None, AutoScroll -> False ]
1439-
} ]
1440-
,
1441-
CurrentValue[ sidebarCell, Editable ] = Inherited
1442-
]
1443-
]
1444-
,
1445-
With[ { boxObject = boxObject, write = write },
1446-
splitDynamicTaskFunction @ NotebookWrite[
1447-
System`NotebookLocationSpecifier[ boxObject, "Before" ],
1448-
write,
1449-
None,
1450-
AutoScroll -> False
1451-
]
1432+
With[ { boxObject = boxObject, write = write },
1433+
splitDynamicTaskFunction @ NotebookWrite[
1434+
System`NotebookLocationSpecifier[ boxObject, "Before" ],
1435+
write,
1436+
None,
1437+
AutoScroll -> False
14521438
]
1453-
];
1439+
]
14541440

14551441
$dynamicTrigger++;
14561442
$lastDynamicUpdate = AbsoluteTime[ ];
@@ -2384,23 +2370,10 @@ WriteChatOutputCell[
23842370
new_Cell,
23852371
info: KeyValuePattern @ { "ExpressionUUID" -> uuid_String, "ScrollOutput" -> scroll_ }
23862372
] := Enclose[
2387-
Module[ { output, input, sidebarQ, sidebarCell },
2373+
Module[ { output, input, sidebarQ },
23882374
sidebarQ = cellTaggedQ[ cell, "SidebarTopCell" ];
23892375
input = PreviousCell[ cell, CellStyle -> If[ sidebarQ, "NotebookAssistant`Sidebar`ChatInput", "ChatInput" ] ]; (* kind of a hack, but we know there should be a corresponding ChatInput cell *)
2390-
If[ sidebarQ,
2391-
sidebarCell = ConfirmMatch[ ParentCell @ ParentCell @ cell, _CellObject, "SidebarCellWriteChatOutputCell" ];
2392-
ConfirmMatch[ cellTaggedQ[ sidebarCell, "NotebookAssistantSidebarCell" ], True, "SidebarCellWriteChatOutputCellTaggedQ" ];
2393-
WithCleanup[
2394-
FrontEndExecute[ {
2395-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
2396-
FrontEnd`NotebookWrite[ cell, new, None, AutoScroll -> False ]
2397-
} ]
2398-
,
2399-
CurrentValue[ sidebarCell, Editable ] = Inherited
2400-
]
2401-
,
2402-
NotebookWrite[ cell, new, None, AutoScroll -> False ]
2403-
];
2376+
NotebookWrite[ cell, new, None, AutoScroll -> False ];
24042377
output = NextCell[ input, CellTags -> uuid ]; (* we set the uuid previously *)
24052378
(* The cell expression was specifically constructed that the UUID appears first in the CellTags *)
24062379
CurrentValue[ output, CellTags ] = Replace[ new, Cell[ ___, CellTags -> { uuid, rest___ }, ___ ] :> { rest } ]; (* an empty list clears the CellTags option *)
@@ -3245,18 +3218,7 @@ throwFailureToChatOutput // endDefinition;
32453218
(*writeErrorCell*)
32463219
writeErrorCell // beginDefinition;
32473220
writeErrorCell[ cell_CellObject, as_ ] /; TrueQ[ $SidebarChat ] := Enclose[
3248-
(* topParentCell is blocked from recursing past a "SidebarTopCell", but we know the parent distance to the side bar cell if in a side bar chat *)
3249-
With[ { sidebarCell = ConfirmMatch[ ParentCell @ ParentCell @ target, _CellObject, "SidebarCellPrintAfter" ] },
3250-
createFETask @ WithCleanup[
3251-
FrontEndExecute[ {
3252-
FrontEnd`SetOptions[ sidebarCell, Editable -> True ],
3253-
FrontEnd`NotebookWrite[ cell, errorCell @ as ]
3254-
} ]
3255-
,
3256-
CurrentValue[ sidebarCell, Editable ] = Inherited
3257-
];
3258-
Null
3259-
],
3221+
createFETask @ NotebookWrite[ cell, errorCell @ as ],
32603222
throwInternalFailure
32613223
]
32623224
writeErrorCell[ cell_CellObject, as_ ] := (createFETask @ NotebookWrite[ cell, errorCell @ as ]; Null);

0 commit comments

Comments
 (0)