From e4b45f1bd99357316870e64b7ac0d10b0ccea8dd Mon Sep 17 00:00:00 2001 From: Nish2005karsh Date: Sat, 13 Jun 2026 23:18:14 +0530 Subject: [PATCH] fix(gui): preserve text selection in code blocks on mouse leave Closes #3850 Problem: Text selected within a chat code block is lost as soon as the cursor leaves the code block while dragging, making it hard to copy a portion of generated code. Root cause: The rendered code block element (StyledPre in gui/src/components/StyledMarkdownPreview/SyntaxHighlightedPre.tsx) had no explicit user-select rule. With the scrollable, fixed-max-height
, a
partial drag-selection could be dropped when the cursor moved outside the
element's bounds.

Fix: Explicitly mark the 
 as user-select: text (with -webkit- prefix)
so selections persist regardless of where the cursor moves.

Minimal, CSS-only change scoped to the chat code block. No behavior change
for copy buttons or apply actions.
---
 .../StyledMarkdownPreview/SyntaxHighlightedPre.tsx           | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gui/src/components/StyledMarkdownPreview/SyntaxHighlightedPre.tsx b/gui/src/components/StyledMarkdownPreview/SyntaxHighlightedPre.tsx
index 6e4fc3e2be5..527252d74c0 100644
--- a/gui/src/components/StyledMarkdownPreview/SyntaxHighlightedPre.tsx
+++ b/gui/src/components/StyledMarkdownPreview/SyntaxHighlightedPre.tsx
@@ -26,6 +26,11 @@ const StyledPre = styled.pre<{ theme: any }>`
   max-height: 40vh;
   overflow-y: scroll !important;
 
+  /* Keep code text selectable so a partial selection isn't lost when the
+     cursor leaves the code block while dragging (see issue #3850). */
+  user-select: text;
+  -webkit-user-select: text;
+
   ${(props) => generateThemeStyles(props.theme)}
 `;