mirror of
https://github.com/block/buzz.git
synced 2026-11-24 18:21:59 +00:00
Picked people (channel members and directory results) now render as
atomic composer chips like agents already did, and the recipient a send
notifies comes from the same occurrence scan that draws the chips.
- Backspace right after a chip removes the trailing space first and the
whole chip second, for people and agents alike; Left and Right step
over a chip as one unit. The agent chip previously broke into plain
`@Scou` on the second Backspace because an undo heuristic mistook any
Backspace landing on earlier typed text for Undo. Undo and Redo are
now detected explicitly through an `Actions` override of
`UndoTextIntent`/`RedoTextIntent` around the field, so the editing
formatter leaves restored values exact and widens real deletions.
- `mentionOccurrences` opens a mention after `(`, `[` and `{` as the
query trigger already did, so `see (@Bob` picked after a bracket
notifies Bob, and the typed exact-member fallback accepts the same
brackets. Draft pruning, rendering and send resolution share it.
- Deleting or editing a chip removes its recipient; text left behind
notifies nobody. Typed, unpicked names keep their existing behaviour,
visible draft text stays `@Label`, and qualified namesake labels still
render as coloured text.
- Person chips use key `composer-person-mention-chip` with semantics
`Mention: <name>` and an `@` prefix; agent chips keep their key, bot
icon and `Agent mention:` semantics. Chip widgets, the editing
formatter and the history action move to `composer_chips.dart`.
Tests: a compose bar journey covers person chip insertion, two-Backspace
removal of person and agent chips, arrow stepping, chip deletion sending
no recipient, bracket-prefixed picks and space-selected names notifying,
and the typed fallback after a bracket; `mention_bindings_test` gains
bracket rows. `flutter analyze`, `dart format` and the full mobile
`flutter test` suite pass.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Matt Toohey <contact@matttoohey.com>
159 lines
4.8 KiB
Dart
159 lines
4.8 KiB
Dart
part of '../compose_bar.dart';
|
|
|
|
class _ComposerBuzzLinkChip extends StatelessWidget {
|
|
final IconData icon;
|
|
final String label;
|
|
final String semanticLabel;
|
|
final TextStyle textStyle;
|
|
|
|
const _ComposerBuzzLinkChip({
|
|
required this.icon,
|
|
required this.label,
|
|
required this.semanticLabel,
|
|
required this.textStyle,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final style = textStyle.copyWith(
|
|
color: context.colors.primary,
|
|
fontWeight: FontWeight.w600,
|
|
height: 1,
|
|
);
|
|
final fontSize = style.fontSize ?? 16;
|
|
return Semantics(
|
|
label: semanticLabel,
|
|
excludeSemantics: true,
|
|
child: Container(
|
|
key: ValueKey('composer-buzz-link-chip:$label'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 1),
|
|
decoration: BoxDecoration(
|
|
color: context.colors.primary.withValues(alpha: 0.16),
|
|
borderRadius: BorderRadius.circular(Radii.sm),
|
|
border: Border.all(
|
|
color: context.colors.primary.withValues(alpha: 0.12),
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: fontSize * 0.95, color: context.colors.primary),
|
|
const SizedBox(width: Grid.quarter + 1),
|
|
Text(label, style: style),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// One selected mention: a person (`@` prefix) or an agent (bot icon).
|
|
/// Semantics name the chip once, so a screen reader has one stop per
|
|
/// mention rather than its hidden source characters.
|
|
class _ComposerMentionChip extends StatelessWidget {
|
|
final String label;
|
|
final bool isAgent;
|
|
final TextStyle textStyle;
|
|
|
|
const _ComposerMentionChip({
|
|
required this.label,
|
|
required this.isAgent,
|
|
required this.textStyle,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final style = textStyle.copyWith(
|
|
color: context.colors.primary,
|
|
fontWeight: FontWeight.w500,
|
|
height: 1,
|
|
);
|
|
final fontSize = style.fontSize ?? 16;
|
|
|
|
return Semantics(
|
|
label: isAgent ? 'Agent mention: $label' : 'Mention: $label',
|
|
excludeSemantics: true,
|
|
child: Container(
|
|
key: ValueKey(
|
|
isAgent
|
|
? 'composer-agent-mention-chip'
|
|
: 'composer-person-mention-chip',
|
|
),
|
|
padding: const EdgeInsets.fromLTRB(
|
|
Grid.half,
|
|
Grid.quarter + 1,
|
|
Grid.half,
|
|
Grid.quarter,
|
|
),
|
|
decoration: BoxDecoration(
|
|
// The composer surface is already tinted, so the body chip's
|
|
// low-opacity fill disappears here. Keep the same chip geometry
|
|
// while giving this editable token enough contrast to read as one.
|
|
color: context.colors.primary.withValues(alpha: 0.16),
|
|
borderRadius: BorderRadius.circular(Radii.sm),
|
|
border: Border.all(
|
|
color: context.colors.primary.withValues(alpha: 0.12),
|
|
),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
if (isAgent) ...[
|
|
Icon(
|
|
BuzzIcons.bot,
|
|
size: fontSize * 0.95,
|
|
color: context.colors.primary,
|
|
),
|
|
const SizedBox(width: Grid.quarter),
|
|
Text(label, style: style),
|
|
] else
|
|
Text('@$label', style: style),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Routes user edits through [_MarkdownEditingController.formatUserEdit] so
|
|
/// composer chips follow their editing rules.
|
|
class _ComposerChipEditingFormatter extends TextInputFormatter {
|
|
final _MarkdownEditingController controller;
|
|
|
|
_ComposerChipEditingFormatter(this.controller);
|
|
|
|
@override
|
|
TextEditingValue formatEditUpdate(
|
|
TextEditingValue oldValue,
|
|
TextEditingValue newValue,
|
|
) => controller.formatUserEdit(oldValue, newValue);
|
|
}
|
|
|
|
/// Marks Undo and Redo for [_MarkdownEditingController.formatUserEdit].
|
|
/// `UndoHistory` lets an ancestor override its undo and redo actions; this
|
|
/// one flags the controller while the default action restores the value, so
|
|
/// the formatter can tell a restored value from a key press that happens to
|
|
/// land on earlier text.
|
|
class _ComposerHistoryAction<T extends Intent> extends Action<T> {
|
|
final _MarkdownEditingController controller;
|
|
|
|
_ComposerHistoryAction(this.controller);
|
|
|
|
@override
|
|
bool isEnabled(T intent, [BuildContext? context]) =>
|
|
callingAction?.isEnabled(intent) ?? false;
|
|
|
|
@override
|
|
Object? invoke(T intent, [BuildContext? context]) {
|
|
final history = callingAction;
|
|
if (history == null) return null;
|
|
controller._applyingHistory = true;
|
|
try {
|
|
return history.invoke(intent);
|
|
} finally {
|
|
controller._applyingHistory = false;
|
|
}
|
|
}
|
|
}
|