File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -328,6 +328,22 @@ describe("ChatMarkdown headings", () => {
328328 } ) ;
329329} ) ;
330330
331+ describe ( "ChatMarkdown inline code selection" , ( ) => {
332+ it ( "selects the whole inline code span on double-click, but only a word in fenced code" , async ( ) => {
333+ setup ( ) ;
334+ await using screen = await renderText (
335+ "Run `migration-gate --dry-run` first.\n\n```txt\nfenced-block word\n```" ,
336+ ) ;
337+ await userEvent . dblClick ( screen . getByText ( "migration-gate --dry-run" ) ) ;
338+ expect ( window . getSelection ( ) ?. toString ( ) ) . toBe ( "migration-gate --dry-run" ) ;
339+
340+ window . getSelection ( ) ?. removeAllRanges ( ) ;
341+ const fenced = screen . container . querySelector ( "pre code" ) ! ;
342+ await userEvent . dblClick ( fenced , { position : { x : 4 , y : 4 } } ) ;
343+ expect ( window . getSelection ( ) ?. toString ( ) ) . not . toContain ( "word" ) ;
344+ } ) ;
345+ } ) ;
346+
331347describe ( "ChatMarkdown Windows file links" , ( ) => {
332348 const environmentId = EnvironmentId . make ( "env-windows" ) ;
333349 const renderWindows = ( text : string , parseRawHtml : boolean ) =>
Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ import React, {
7474 Suspense ,
7575 type ComponentProps ,
7676 type ClipboardEvent as ReactClipboardEvent ,
77+ type MouseEvent as ReactMouseEvent ,
7778 use ,
7879 memo ,
7980 useLayoutEffect ,
@@ -942,6 +943,11 @@ function markdownHeadingRenderer(level: 1 | 2 | 3 | 4 | 5 | 6) {
942943 } ;
943944}
944945
946+ // Native word selection stops at hyphens and dots, so a double-click takes the whole span.
947+ function selectInlineCode ( event : ReactMouseEvent < HTMLElement > ) {
948+ window . getSelection ( ) ?. selectAllChildren ( event . currentTarget ) ;
949+ }
950+
945951const CHAT_MARKDOWN_COMPONENTS = {
946952 h1 : markdownHeadingRenderer ( 1 ) ,
947953 h2 : markdownHeadingRenderer ( 2 ) ,
@@ -1334,6 +1340,11 @@ const CHAT_MARKDOWN_COMPONENTS = {
13341340 inlineCodeFilePathCandidate ( codeText ) ?? codeText . trim ( ) ,
13351341 ) ;
13361342 }
1343+ return (
1344+ < code { ...props } className = { className } onDoubleClick = { selectInlineCode } >
1345+ { children }
1346+ </ code >
1347+ ) ;
13371348 }
13381349 return (
13391350 < code { ...props } className = { className } >
You can’t perform that action at this time.
0 commit comments