Skip to content

Commit 4f5f0a2

Browse files
authored
Merge pull request #1390 from WolframResearch/bugfix/Optimization1
Bugfix/optimization1
2 parents ff5f105 + 179240a commit 4f5f0a2

File tree

21 files changed

+191
-163
lines changed

21 files changed

+191
-163
lines changed

DarkModeSupport/TextResources/ChatbookResources.tr

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9858,15 +9858,14 @@ VX/aMEEQzrerjFhhelYAzofFB3r8AgApYdcE
98589858
Editable->True,
98599859
Selectable->False,
98609860
CellMargins->{{0, 0}, {0, 0}},
9861-
Initialization:>(AttachCell[
9862-
EvaluationCell[],
9863-
Cell["", CellTags -> "NotebookAssistantSidebarAttachedHelperCell"], {
9864-
Left, Top}, 0, {Left, Top}]; Needs["Wolfram`Chatbook`" -> None];
9865-
CurrentValue[
9866-
EvaluationCell[], TaggingRules] = <|
9867-
"ChatNotebookSettings" ->
9868-
Wolfram`Chatbook`NotebookAssistanceSidebarSettings[],
9869-
"ConversationTitle" -> ""|>),
9861+
Initialization:>
9862+
With[{Typeset`ec = EvaluationCell[]}, AttachCell[Typeset`ec,
9863+
Cell["", CellTags -> "NotebookAssistantSidebarAttachedHelperCell"], {
9864+
Left, Top}, 0, {Left, Top}]; Needs["Wolfram`Chatbook`" -> None];
9865+
CurrentValue[Typeset`ec, TaggingRules] = <|
9866+
"ChatNotebookSettings" ->
9867+
Wolfram`Chatbook`NotebookAssistanceSidebarSettings[],
9868+
"ConversationTitle" -> ""|>],
98709869
CellFrameMargins->0,
98719870
ShowCursorTracker->False,
98729871
LineSpacing->{1, 0},
@@ -9877,8 +9876,8 @@ VX/aMEEQzrerjFhhelYAzofFB3r8AgApYdcE
98779876
GrayLevel[0.95],
98789877
RGBColor[0.1882352, 0.2078431, 0.2274509]],
98799878
CellTags->
9880-
"NotebookAssistantSidebarCell",ExpressionUUID->"ceb7a8fa-8e67-e442-9d90-\
9881-
64f5b8406e2d"],
9879+
"NotebookAssistantSidebarCell",ExpressionUUID->"25bcf740-0257-dc49-a8f2-\
9880+
05e981f6bfae"],
98829881

98839882
"SidebarIconHide" -> (GraphicsBox[{
98849883
Thickness[0.125],

Developer/Resources/FrontEndResources/SideBarChat/NotebookAssistantSidebarCell.wl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ Cell[
3232
CellTags -> "NotebookAssistantSidebarCell",
3333
Editable -> True,
3434
FontSize -> 0.5, (* needed to workaround line wrapping issue where newlines are given their full line-height based on the FontSize *)
35-
Initialization :> (
36-
AttachCell[ EvaluationCell[ ], Cell[ "", CellTags -> "NotebookAssistantSidebarAttachedHelperCell" ], { Left, Top }, 0, { Left, Top } ];
37-
Needs[ "Wolfram`Chatbook`" -> None ];
38-
CurrentValue[ EvaluationCell[ ], TaggingRules ] = <| "ChatNotebookSettings" -> Wolfram`Chatbook`NotebookAssistanceSidebarSettings[ ], "ConversationTitle" -> "" |>),
35+
Initialization :>
36+
With[ { Typeset`ec = EvaluationCell[ ] },
37+
AttachCell[ Typeset`ec, Cell[ "", CellTags -> "NotebookAssistantSidebarAttachedHelperCell" ], { Left, Top }, 0, { Left, Top } ];
38+
Needs[ "Wolfram`Chatbook`" -> None ];
39+
CurrentValue[ Typeset`ec, TaggingRules ] = <| "ChatNotebookSettings" -> Wolfram`Chatbook`NotebookAssistanceSidebarSettings[ ], "ConversationTitle" -> "" |>],
3940
LineIndent -> 0,
4041
LineSpacing -> { 1, 0 },
4142
Magnification -> 1.,

Source/Chatbook/Actions.wl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ disableAssistance[ cell_CellObject ] := (
304304
);
305305

306306
disableAssistance[ nbo_NotebookObject ] := (
307-
CurrentValue[ nbo, { TaggingRules, "ChatNotebookSettings", "Assistance" } ] = False
307+
setCurrentValue[ nbo, { TaggingRules, "ChatNotebookSettings", "Assistance" }, False ]
308308
);
309309

310310
disableAssistance // endDefinition;
@@ -424,16 +424,16 @@ rotateTabPage // endDefinition;
424424
writePageContent // beginDefinition;
425425

426426
writePageContent[ cell_CellObject, newPage_Integer, content: TextData[ $$textData ] ] /; $cloudNotebooks := (
427-
CurrentValue[ cell, { TaggingRules, "PageData", "CurrentPage" } ] = newPage;
428-
CurrentValue[ cell, TaggingRules ] = GeneralUtilities`ToAssociations @ CurrentValue[ cell, TaggingRules ];
427+
setCurrentValue[ cell, { TaggingRules, "PageData", "CurrentPage" }, newPage ];
428+
setCurrentValue[ cell, TaggingRules, GeneralUtilities`ToAssociations @ CurrentValue[ cell, TaggingRules ] ];
429429
NotebookWrite[ cell, ReplacePart[ NotebookRead @ cell, 1 -> content ] ];
430430
)
431431

432432
writePageContent[ cell_CellObject, newPage_Integer, content: TextData[ $$textData ] ] := (
433433
SelectionMove[ cell, All, CellContents, AutoScroll -> False ];
434434
NotebookWrite[ parentNotebook @ cell, content, None, AutoScroll -> False ];
435435
SelectionMove[ cell, After, Cell, AutoScroll -> False ];
436-
CurrentValue[ cell, { TaggingRules, "PageData", "CurrentPage" } ] = newPage;
436+
setCurrentValue[ cell, { TaggingRules, "PageData", "CurrentPage" }, newPage ];
437437
SetOptions[ cell, CellAutoOverwrite -> True, GeneratedCell -> True ]
438438
);
439439

@@ -1120,13 +1120,13 @@ setChatSectionSettings // beginDefinition;
11201120

11211121
setChatSectionSettings[ cell_CellObject, settings_Association ] :=
11221122
Module[ { cellSettings, nbSettings, newSettings },
1123-
KeyValueMap[ Function[ CurrentValue[ cell, { TaggingRules, "ChatNotebookSettings", #1 } ] = #2 ], settings ];
1123+
KeyValueMap[ Function[ setCurrentValue[ cell, { TaggingRules, "ChatNotebookSettings", #1 }, #2 ] ], settings ];
11241124

11251125
(* The rest of this is a workaround for bug 435058 *)
11261126
cellSettings = CurrentValue[ cell, { TaggingRules, "ChatNotebookSettings" } ];
11271127
nbSettings = CurrentValue[ parentNotebook @ cell, { TaggingRules, "ChatNotebookSettings" } ];
11281128
newSettings = Complement[ cellSettings, nbSettings ];
1129-
CurrentValue[ cell, { TaggingRules, "ChatNotebookSettings" } ] = newSettings;
1129+
setCurrentValue[ cell, { TaggingRules, "ChatNotebookSettings" }, newSettings ];
11301130
];
11311131

11321132
setChatSectionSettings // endDefinition;
@@ -1228,7 +1228,7 @@ ExclusionToggle[ nbo_NotebookObject, cellObjects: { __CellObject } ] :=
12281228
cells = ConfirmMatch[ NotebookRead @ cellObjects, { __Cell } ];
12291229
excluded = MatchQ[ cells, { Cell[ __, "ChatExcluded", ___ ], ___ } ];
12301230
toggled = ConfirmMatch[ If[ excluded, includeChatCells @ cells, excludeChatCells @ cells ], { __Cell } ];
1231-
CurrentValue[ cellObjects, Deletable ] = True;
1231+
setCurrentValue[ cellObjects, Deletable, True ];
12321232
NotebookDelete @ cellObjects;
12331233
NotebookWrite[ nbo, toggled, All ]
12341234
];
@@ -1260,7 +1260,7 @@ WidgetSend // beginDefinition;
12601260
WidgetSend[ cell_CellObject ] := withChatState @
12611261
Block[ { $alwaysOpen = True, cellPrint = cellPrintAfter @ cell, $finalCell = cell, $AutomaticAssistance = True },
12621262
(* TODO: this is currently the only UI method to turn this back on *)
1263-
CurrentValue[ parentNotebook @ cell, { TaggingRules, "ChatNotebookSettings", "Assistance" } ] = True;
1263+
setCurrentValue[ parentNotebook @ cell, { TaggingRules, "ChatNotebookSettings", "Assistance" }, True ];
12641264
SendChat @ cell
12651265
];
12661266

Source/Chatbook/ChatModes/Evaluate.wl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ evaluateWorkspaceChat[ nbo_NotebookObject, Dynamic[ input: _Symbol|_CurrentValue
4747
NotebookWrite[ nbo, cell ];
4848
moveChatInputToBottom @ nbo;
4949
cellObject = ConfirmMatch[ First[ Cells[ nbo, CellTags -> uuid ], $Failed ], _CellObject, "CellObject" ];
50-
CurrentValue[ cellObject, CellTags ] = { };
50+
setCurrentValue[ cellObject, CellTags, { } ];
5151
ConfirmMatch[ ChatCellEvaluate[ cellObject, nbo ], _ChatObject|Null, "ChatCellEvaluate" ]
5252
],
5353
throwInternalFailure
@@ -85,17 +85,19 @@ evaluateSidebarChat[ nbo_NotebookObject, sidebarCell_CellObject, input_, Dynamic
8585
NotebookWrite[ System`NotebookLocationSpecifier[ lastDockedCell, "After" ], makeSidebarChatScrollingCell[ nbo, sidebarCell, { cell } ] ];
8686
scrollablePaneCell = ConfirmMatch[ First[ Cells[ sidebarCell, CellTags -> "SidebarScrollingContentCell" ], $Failed ], _CellObject, "UpdatedSidebarScrollableCell" ];
8787
, (* ELSE *)
88-
If[ Cells[ scrollablePaneCell, CellTags -> "SidebarTopCell" ] === { }, (* rewrite the entire cell if it has no content *)
89-
NotebookWrite[ scrollablePaneCell, makeSidebarChatScrollingCell[ nbo, sidebarCell, { cell } ] ];
90-
scrollablePaneCell = ConfirmMatch[ First[ Cells[ sidebarCell, CellTags -> "SidebarScrollingContentCell" ], $Failed ], _CellObject, "NoNewScrollingContentCell" ];
91-
,
92-
lastContentCell = ConfirmMatch[ Last[ Cells[ scrollablePaneCell, CellTags -> "SidebarTopCell" ], $Failed ], _CellObject, "NoSidebarScrollingContentCell" ];
93-
NotebookWrite[ System`NotebookLocationSpecifier[ lastContentCell, "After" ], cell ]
88+
With[ { chatCells = Cells[ scrollablePaneCell, CellTags -> "SidebarTopCell" ]},
89+
If[ chatCells === { }, (* rewrite the entire cell if it has no content; this removes the "AskAnything" content *)
90+
NotebookWrite[ scrollablePaneCell, makeSidebarChatScrollingCell[ nbo, sidebarCell, { cell } ] ];
91+
scrollablePaneCell = ConfirmMatch[ First[ Cells[ sidebarCell, CellTags -> "SidebarScrollingContentCell" ], $Failed ], _CellObject, "NoNewScrollingContentCell" ];
92+
,
93+
lastContentCell = ConfirmMatch[ Last[ chatCells, $Failed ], _CellObject, "NoSidebarScrollingContentCell" ];
94+
NotebookWrite[ System`NotebookLocationSpecifier[ lastContentCell, "After" ], cell ]
95+
]
9496
]
9597
];
9698

9799
cellObject = ConfirmMatch[ Last[ Cells[ scrollablePaneCell, CellTags -> uuid ], $Failed ], _CellObject, "SidebarChatInputCellObject" ];
98-
CurrentValue[ cellObject, CellTags ] = "SidebarTopCell";
100+
setCurrentValue[ cellObject, CellTags, "SidebarTopCell" ];
99101
ConfirmMatch[ ChatCellEvaluate[ cellObject, nbo ], _ChatObject|Null, "ChatCellEvaluate" ]
100102
],
101103
throwInternalFailure

Source/Chatbook/ChatModes/NotebookFocus.wl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ focusedNotebookDisplay[ chatNB_, appContainer_ ] := Enclose[
6666
focused = FirstCase[ info, KeyValuePattern[ "Focused" -> True ], current ];
6767

6868
(* focusedNotebookDisplay is dynamically updated so this TaggingRules value should be kept current *)
69-
CurrentValue[ chatNB, { TaggingRules, "FocusWindowTitle" } ] = Lookup[ focused, "WindowTitle", None ];
69+
setCurrentValue[ chatNB, { TaggingRules, "FocusWindowTitle" }, Lookup[ focused, "WindowTitle", None ] ];
7070

7171
label = If[ MatchQ[ appContainer, _CellObject ],
7272
Grid[

0 commit comments

Comments
 (0)