mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
fix(mobile): let code scroll under the code block copy button (#9612)
## 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 <wesbillman@users.noreply.github.com> Co-authored-by: Carl <32a2e2c9d428ee08902cab75d956da2c1d235a22d4766b0dd4138bf6e2e5db1d@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user