diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index bd16aadff..c49161ff3 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -444,9 +444,11 @@ void UISceneNode::setThreadPool( const std::shared_ptr& threadPool ) } static std::string getErrorContext( size_t offset, std::string_view content ) { - static constexpr auto CONTEXT_LENGTH = 40; - std::size_t left = std::max( 0ul, offset >= CONTEXT_LENGTH ? offset - CONTEXT_LENGTH : 0ul ); - std::size_t right = std::min( content.size(), offset + 40 ); + static constexpr std::size_t CONTEXT_LENGTH = 40; + std::size_t minVal = offset >= CONTEXT_LENGTH ? offset - CONTEXT_LENGTH : 0; + std::size_t maxVal = offset + CONTEXT_LENGTH; + std::size_t left = std::max( static_cast( 0ul ), minVal ); + std::size_t right = std::min( content.size(), maxVal ); return std::string{ content.substr( left, right - left ) }; } diff --git a/src/tools/ecode/plugins/aiassistant/chatui.cpp b/src/tools/ecode/plugins/aiassistant/chatui.cpp index e52f25703..fd039f62f 100644 --- a/src/tools/ecode/plugins/aiassistant/chatui.cpp +++ b/src/tools/ecode/plugins/aiassistant/chatui.cpp @@ -2651,12 +2651,15 @@ void LLMChatUI::addPermissionUI( const acp::RequestPermissionRequest& req, UIWidget* LLMChatUI::addMarkdownBubble( const std::string& layout, const std::string& markdown ) { find( "chat_presentation" )->setVisible( false ); UIWidget* chat = mChatsList->getUISceneNode()->loadLayoutFromString( layout, mChatsList ); - if ( chat ) + if ( chat && !markdown.empty() ) chat->asType()->loadFromString( markdown ); return chat; } void LLMChatUI::addPlanBubble( const std::string& markdown ) { + if ( markdown.empty() ) + return; + runOnMainThread( [this, markdown] { removeWaitingBubble(); @@ -2810,7 +2813,10 @@ void LLMChatUI::addToolCallUpdate( const nlohmann::json& msg ) { } void LLMChatUI::updateThinkingBubble( const std::string& chunk ) { - runOnMainThread( [this, chunk] { + if ( chunk.empty() ) + return; + + runOnMainThread( [this, chunk = std::move( chunk )] { removeWaitingBubble(); UIWidget* bubble = nullptr;