Skip to content

Commit

Permalink
Merge pull request #945 from WolframResearch/bugfix/454506
Browse files Browse the repository at this point in the history
Bugfix: Avoid attaching duplicate chat input cells and preserve text
  • Loading branch information
rhennigan authored Nov 22, 2024
2 parents 44871b4 + 13858cf commit 605ecdf
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Source/Chatbook/ChatModes/UI.wl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ writeWorkspaceChatSubDockedCell[ nbo_NotebookObject, content_ ] := (
CurrentValue[ nbo, DockedCells ] = Inherited;
CurrentValue[ nbo, DockedCells ] = {
First @ Replace[ AbsoluteCurrentValue[ nbo, DockedCells ], c_Cell :> {c} ],
makeWorkspaceChatSubDockedCellExpression[ content ] }
makeWorkspaceChatSubDockedCellExpression[ content ] };
(* Rewriting docked cells seems to steal focus from the chat input field, so restore it here: *)
If[ SelectedCells @ nbo === { }, moveToChatInputField[ nbo, True ] ]
)

writeWorkspaceChatSubDockedCell[ nbo_NotebookObject, WindowTitle ] := writeWorkspaceChatSubDockedCell[
Expand Down Expand Up @@ -318,7 +320,18 @@ attachWorkspaceChatInput // beginDefinition;
attachWorkspaceChatInput[ nbo_NotebookObject ] := attachWorkspaceChatInput[ nbo, Bottom ]

attachWorkspaceChatInput[ nbo_NotebookObject, location : Top|Bottom ] := Enclose[
Module[ { attached },
Catch @ Module[ { current, tags, attached },

current = Cells[ nbo, AttachedCell -> True, CellStyle -> "ChatInputField" ];
tags = CurrentValue[ current, CellTags ];

(* Check if cell is already attached in the specified location: *)
If[ MatchQ[ tags, { { ___, ToString @ location, ___ } } ],
Throw @ ConfirmMatch[ First[ current, $Failed ], _CellObject, "CurrentCell" ]
];

NotebookDelete @ current;

attached = ConfirmMatch[
AttachCell[
nbo,
Expand Down Expand Up @@ -359,6 +372,7 @@ attachedWorkspaceChatInputCell[ location_String ] := Cell[
{ TaggingRules, "ChatInputString" }
],
String,
ContinuousAction -> True,
$inputFieldOptions
],
$inputFieldFrameOptions
Expand Down

0 comments on commit 605ecdf

Please sign in to comment.