Skip to content

Commit

Permalink
Merge pull request #933 from WolframResearch/932-moving-selection-whi…
Browse files Browse the repository at this point in the history
…le-generating-content-suggestions-can-generate-an-internal-failure

Bugfix: Fixed an error that could occur while moving the selection during content suggestions
  • Loading branch information
rhennigan authored Nov 18, 2024
2 parents 258b80a + 94ef0c8 commit 0d26055
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions Source/Chatbook/ChatModes/ContentSuggestions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -675,19 +675,22 @@ getSurroundingWLCode // beginDefinition;

getSurroundingWLCode[ context_String ] := Enclose[
Catch @ Module[ { strings, boxes },
strings = First @ ConfirmMatch[
StringCases[
context,
StringExpression[
"```wl\n",
a___ /; StringFreeQ[ a, "```" ],
$wlPlaceholderString,
b___ /; StringFreeQ[ b, "```" ],
"\n```"
] :> { a, b },
1
strings = ConfirmMatch[
First[
StringCases[
context,
StringExpression[
"```wl\n",
a___ /; StringFreeQ[ a, "```" ],
$wlPlaceholderString,
b___ /; StringFreeQ[ b, "```" ],
"\n```"
] :> { a, b },
1
],
Throw @ { "", "" }
],
{ { _String, _String } },
{ _String, _String },
"Strings"
];

Expand Down Expand Up @@ -761,7 +764,7 @@ postProcessWLSuggestions[ suggestion_String ] := Enclose[
"```" ~~ WhitespaceCharacter... ~~ EndOfLine
}
],
Longest[ "```"|"``" ]
Longest @ Repeated[ "`", { 1, 3 } ]
];

noLabels = StringTrim @ StringDelete[ noBlocks, $$inLabel ];
Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/Common.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ maskOpenAIKey[ expr_ ] :=
(* ::Subsection::Closed:: *)
(*markdownCodeBlock*)
markdownCodeBlock[ as_Association? AssociationQ ] :=
"```\n<|\n" <> StringRiffle[ ruleToString /@ Normal[ as, Association ], "\n" ] <> "\n|>\n```\n";
"```\n<|\n" <> StringRiffle[ ruleToString /@ Normal[ as, Association ], ",\n" ] <> "\n|>\n```\n";

markdownCodeBlock[ expr_ ] := StringJoin[
"```\n",
Expand Down

0 comments on commit 0d26055

Please sign in to comment.