From 8306e387421e7d0cb04a0768de7dda9aa427adbe Mon Sep 17 00:00:00 2001 From: Wes Date: Thu, 19 Nov 2026 07:28:06 -0700 Subject: [PATCH] fix(mobile): let code scroll under the code block copy button (#9612) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What changed The copy button on a message code block reserved a fixed 40px column beside the horizontal scroller, so every line was clipped about 40px short of the block's right edge. This was most visible on narrow phones. The fix matches buzz-app desktop (`Markdown.module.css`, `.codeActions`): - The horizontal scroller now spans the whole block. - The copy button floats in the top-right corner on an opaque chip, so code scrolled under it never collides with the icon. On an own-message bubble the chip is the code tint blended over the outgoing fill, so it matches the block. - The end padding moves inside the scroll content, so every line end can still be scrolled clear of the button. - The language label keeps its right inset, so it never runs under the button. ## Why nothing gets worse Same tap target, icon, copy behavior and block insets. The only visual change is that code now uses the width the gutter used to take. Long lines in the button's row pass under the opaque chip while scrolled, as they do on desktop. ## Testing - `message_content_test.dart` "renders code block with language tag" now asserts that the scroller spans the block inside its border and that the copy button overlaps the scroller. Without the production change it fails (`Expected: 798.0, Actual: 746.0`), and it passes with it. - Before/after captures were rendered with the real fonts and the mobile appearance theme at iPhone width, for received and own (Chartreuse) bubbles, at rest and scrolled to the end. They are in the screenshots comment. - Pre-commit and pre-push hooks passed. - Not yet exercised in the native app on a device. The iOS "Copy and Delete" screenshot paste issue from the same report is still being diagnosed and is not in this PR yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Wes Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 --- .../features/channels/message_content.dart | 79 +++++++++++-------- .../channels/message_content_test.dart | 12 +++ 2 files changed, 58 insertions(+), 33 deletions(-) diff --git a/mobile/lib/features/channels/message_content.dart b/mobile/lib/features/channels/message_content.dart index 13be35a808..ac5a29d2aa 100644 --- a/mobile/lib/features/channels/message_content.dart +++ b/mobile/lib/features/channels/message_content.dart @@ -1051,6 +1051,8 @@ class _MediaPreviewFallback extends StatelessWidget { } } +const _codeCopyButtonSize = 28.0; + class _MessageCodeBlock extends HookWidget { final String name; final String code; @@ -1099,6 +1101,14 @@ class _MessageCodeBlock extends HookWidget { : [TextSpan(text: shownCode)], [code, name, isDark, ink], ); + // Opaque, so the copy button can share it and hide code scrolled beneath. + // An inked block sits on the outgoing fill, so its tint is blended there. + final surface = ink == null + ? CodeStyle.background(context.colors) + : Color.alphaBlend( + chatCodeTint(ink, 0.14), + ChatColors.of(context).outgoing, + ); return Container( // In a bubble, the vertical margin brings the bubble's 8px vertical // padding up to its 16px side padding, so the block is inset evenly and @@ -1107,9 +1117,7 @@ class _MessageCodeBlock extends HookWidget { ? const EdgeInsets.symmetric(vertical: Grid.xs - Grid.xxs) : const EdgeInsets.only(top: Grid.half), decoration: BoxDecoration( - color: ink == null - ? CodeStyle.background(context.colors) - : chatCodeTint(ink, 0.14), + color: surface, borderRadius: BorderRadius.circular( bubble ? Radii.container - Grid.xs : 12, ), @@ -1120,50 +1128,55 @@ class _MessageCodeBlock extends HookWidget { ), child: Stack( children: [ - // Even 12px insets; the right side also reserves the copy button. - Padding( - padding: const EdgeInsets.fromLTRB( - Grid.twelve, - Grid.twelve, - Grid.twelve + 28, - Grid.twelve, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - mainAxisSize: MainAxisSize.min, - children: [ - if (name.isNotEmpty) - Padding( - padding: const EdgeInsets.only(bottom: Grid.half), - child: Text( - name, - style: context.textTheme.labelSmall?.copyWith( - color: ink ?? context.colors.onSurfaceVariant, - ), + // As on desktop, the code scrolls under the copy button rather than + // beside it, and its end padding keeps every line end reachable. + Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + mainAxisSize: MainAxisSize.min, + children: [ + if (name.isNotEmpty) + Padding( + padding: const EdgeInsets.fromLTRB( + Grid.twelve, + Grid.twelve, + Grid.twelve + _codeCopyButtonSize, + Grid.half, + ), + child: Text( + name, + style: context.textTheme.labelSmall?.copyWith( + color: ink ?? context.colors.onSurfaceVariant, ), ), - SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: RichText( - softWrap: false, - text: TextSpan(style: codeBaseStyle, children: codeSpans), - ), ), - ], - ), + SingleChildScrollView( + scrollDirection: Axis.horizontal, + padding: EdgeInsets.fromLTRB( + Grid.twelve, + name.isEmpty ? Grid.twelve : 0, + Grid.twelve + _codeCopyButtonSize, + Grid.twelve, + ), + child: RichText( + softWrap: false, + text: TextSpan(style: codeBaseStyle, children: codeSpans), + ), + ), + ], ), Positioned( top: Grid.half + Grid.quarter, right: Grid.half + Grid.quarter, child: SizedBox( - width: 28, - height: 28, + width: _codeCopyButtonSize, + height: _codeCopyButtonSize, child: IconButton( onPressed: handleCopy, padding: EdgeInsets.zero, visualDensity: VisualDensity.compact, style: IconButton.styleFrom( tapTargetSize: MaterialTapTargetSize.shrinkWrap, + backgroundColor: surface, ), icon: Icon( isCopied.value ? BuzzIcons.check : BuzzIcons.copy, diff --git a/mobile/test/features/channels/message_content_test.dart b/mobile/test/features/channels/message_content_test.dart index 080312cd78..1808af0dc4 100644 --- a/mobile/test/features/channels/message_content_test.dart +++ b/mobile/test/features/channels/message_content_test.dart @@ -1755,6 +1755,18 @@ void main() { expect(_findRich('void main() {}'), findsWidgets); expect(find.text('dart'), findsOneWidget); + + // The copy button floats over the code, as on desktop, instead of + // reserving a column: the scroller spans the block inside its border. + final scroller = find.byType(SingleChildScrollView).last; + final block = find + .ancestor(of: scroller, matching: find.byType(Container)) + .first; + expect(tester.getSize(scroller).width, tester.getSize(block).width - 2); + expect( + tester.getRect(find.byIcon(BuzzIcons.copy)).right, + lessThan(tester.getRect(scroller).right), + ); }); });