Highlight the active chat in session lists

This commit is contained in:
2026-10-25 17:17:43 +00:00
parent 7fe106b426
commit a58d820d43
8 changed files with 268 additions and 35 deletions
@@ -26,10 +26,12 @@ class ChatSessionsBody extends StatelessWidget {
required this.onClearSearch,
required this.isUnseen,
required this.errorFor,
this.activeSessionId,
this.onDismissError,
});
final List<JsonMap> sessions;
final String? activeSessionId;
final String query;
final bool loading;
final String? error;
@@ -80,6 +82,7 @@ class ChatSessionsBody extends StatelessWidget {
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoSessionList(
sections: sections,
activeSessionId: activeSessionId,
emptyMessage: visible.isEmpty ? emptyMessage : null,
duplicateTitles: duplicateTitles,
onOpen: onOpen,
@@ -96,6 +99,7 @@ class ChatSessionsBody extends StatelessWidget {
}
return MaterialSessionList(
sections: sections,
activeSessionId: activeSessionId,
emptyMessage: visible.isEmpty ? emptyMessage : null,
duplicateTitles: duplicateTitles,
onOpen: onOpen,
@@ -203,6 +203,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
children: [
ChatSessionsBody(
sessions: _controller.sessions,
activeSessionId: widget.activeSessionId,
query: _search.text,
loading: _controller.loading,
error: _controller.error,
@@ -25,10 +25,12 @@ class CupertinoSessionList extends StatelessWidget {
required this.onClearSearch,
required this.isUnseen,
required this.errorFor,
this.activeSessionId,
this.onDismissError,
});
final List<ChatSessionSection> sections;
final String? activeSessionId;
final String? emptyMessage;
final Set<String> duplicateTitles;
final ValueChanged<JsonMap> onOpen;
@@ -96,6 +98,7 @@ class CupertinoSessionList extends StatelessWidget {
return [
_CupertinoSessionRow(
session: session,
selected: id == activeSessionId,
duplicateTitles: duplicateTitles,
unseen: isUnseen(session),
onOpen: onOpen,
@@ -118,6 +121,7 @@ class CupertinoSessionList extends StatelessWidget {
class _CupertinoSessionRow extends StatelessWidget {
const _CupertinoSessionRow({
required this.session,
required this.selected,
required this.duplicateTitles,
required this.unseen,
required this.onOpen,
@@ -129,6 +133,7 @@ class _CupertinoSessionRow extends StatelessWidget {
});
final JsonMap session;
final bool selected;
final Set<String> duplicateTitles;
final bool unseen;
final ValueChanged<JsonMap> onOpen;
@@ -153,41 +158,50 @@ class _CupertinoSessionRow extends StatelessWidget {
final statusStyle = TextStyle(
color: status == 'Closed' ? secondary : theme.primaryColor,
);
return CupertinoListTile(
key: Key('chat-row-$id'),
leading: Icon(sessionCupertinoIcon(session)),
// As on the web: the title with the unread/closed word trailing, then
// the muted `recency · directory · model` line.
title: ChatSessionRowMeta(
meta: chatSessionTitle(session),
status: status,
metaStyle: const TextStyle(),
statusStyle: statusStyle,
),
subtitle: meta.isEmpty
? null
: Text(
meta,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: secondary),
return Semantics(
selected: selected,
child: CupertinoListTile(
key: Key('chat-row-$id'),
backgroundColor: selected
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
: null,
leading: Icon(
sessionCupertinoIcon(session),
color: selected ? theme.primaryColor : null,
),
// As on the web: the title with the unread/closed word trailing, then
// the muted `recency · directory · model` line.
title: ChatSessionRowMeta(
meta: chatSessionTitle(session),
status: status,
metaStyle: const TextStyle(),
statusStyle: statusStyle,
),
subtitle: meta.isEmpty
? null
: Text(
meta,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: secondary),
),
onTap: () => onOpen(session),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
SessionStarButton(
key: Key('chat-star-$id'),
session: session,
onPressed: () => onStar(session),
),
onTap: () => onOpen(session),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
SessionStarButton(
key: Key('chat-star-$id'),
session: session,
onPressed: () => onStar(session),
),
SessionActionsButton(
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: _select,
),
],
SessionActionsButton(
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: _select,
),
],
),
),
);
}
@@ -25,10 +25,12 @@ class MaterialSessionList extends StatelessWidget {
required this.onClearSearch,
required this.isUnseen,
required this.errorFor,
this.activeSessionId,
this.onDismissError,
});
final List<ChatSessionSection> sections;
final String? activeSessionId;
final String? emptyMessage;
final Set<String> duplicateTitles;
final ValueChanged<JsonMap> onOpen;
@@ -101,6 +103,7 @@ class MaterialSessionList extends StatelessWidget {
return [
_MaterialSessionRow(
session: session,
selected: id == activeSessionId,
duplicateTitles: duplicateTitles,
unseen: isUnseen(session),
onOpen: onOpen,
@@ -123,6 +126,7 @@ class MaterialSessionList extends StatelessWidget {
class _MaterialSessionRow extends StatelessWidget {
const _MaterialSessionRow({
required this.session,
required this.selected,
required this.duplicateTitles,
required this.unseen,
required this.onOpen,
@@ -134,6 +138,7 @@ class _MaterialSessionRow extends StatelessWidget {
});
final JsonMap session;
final bool selected;
final Set<String> duplicateTitles;
final bool unseen;
final ValueChanged<JsonMap> onOpen;
@@ -160,6 +165,9 @@ class _MaterialSessionRow extends StatelessWidget {
);
return ListTile(
key: Key('chat-row-$id'),
selected: selected,
selectedTileColor: theme.colorScheme.secondaryContainer,
selectedColor: theme.colorScheme.onSecondaryContainer,
leading: Icon(sessionMaterialIcon(session)),
// As on the web: the title with the unread/closed word trailing, then
// the muted `recency · directory · model` line.
+44
View File
@@ -0,0 +1,44 @@
# Active chat row highlight
## Fix
The destination already passed its selected session ID to `ChatSessionsScreen`,
but the screen only used it for unread tracking. It never reached the row widgets.
The ID now flows through `ChatSessionsBody` into both native lists.
- Material uses `ListTile.selected` with the theme's secondary-container surface
and matching foreground.
- Cupertino uses selected semantics, the native tertiary-system-fill background
and the theme's primary icon color.
- Selection follows the routed session ID, not its title, hover, unread mark or
list position. Opening another chat moves the highlight; closing the chat
clears it. No navigation or Back behavior changed.
## Verification
- Full `flutter test`: **1,890 passed**; chat/application subset: 560 passed.
- `flutter analyze`: clean. Release web build: passed, isolated output
`build/chat-active-selection-web` (not the served website).
- New row tests cover Material/Cupertino, light/dark, an initially routed chat,
duplicate titles, switching, refresh/reorder/rename, and clearing selection.
Wide list/detail tests check switching; phone coverage checks Back clears it.
- Real browser interaction/captures in
`build/chat-active-selection-{material,material-dark,cupertino-light,cupertino-dark}`.
Persistent selected semantics verified after moving the pointer away and after
reloading the selected chat's URL. Screenshots inspected in all four themes.
No pre-fix browser screenshot was captured; the source diff identifies the
missing state propagation.
## Pixel installation
- Built release **0.1.29882472**, `net.awan.pipelines.next`, with the existing
signing certificate; installed using `adb -s 47241FDAS00DLK install -r`.
App data and sign-in preserved. APK: `build/chat-active-selection-apk/pipelines.apk`.
- On the authorized Pixel 9 Pro XL, temporarily used 2000x2244 to expose the
side-by-side layout. Opened Pipelines Claude, confirmed its row highlighted
and selected=true; opened Pipelines OpenCode, confirmed selection moved and
the Claude row became selected=false. No messages sent or modes changed.
- Native screenshots/XML: `build/chat-active-selection-pixel9/`. Original display,
density, power and timeout settings verified restored; test files removed
from the device. The updated build remains installed.
- No website deployment, public update-feed publication, or shared-service restart.
@@ -51,6 +51,10 @@ void main() {
'at $size', (tester) async {
await _pumpShell(tester, size);
expect(find.text('Select a chat to open it here.'), findsOneWidget);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-a'))).selected,
isFalse,
);
await tester.tap(find.text('First chat'));
await tester.pumpAndSettle();
@@ -59,6 +63,14 @@ void main() {
expect(find.byType(NavigationRail), findsOneWidget);
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
expect(find.text('Second chat'), findsOneWidget);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-a'))).selected,
isTrue,
);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-b'))).selected,
isFalse,
);
// The shell bar keeps the list's controls; the pane bar has the chat's
// title and no Back.
expect(find.byKey(const Key('chat-new-chat')), findsOneWidget);
@@ -76,6 +88,14 @@ void main() {
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('chat-thread-a')), findsNothing);
expect(find.byKey(const ValueKey('chat-thread-b')), findsOneWidget);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-a'))).selected,
isFalse,
);
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-b'))).selected,
isTrue,
);
expect(navigator.canPop(), isFalse);
// The rail still switches destinations with a chat open.
@@ -98,6 +118,13 @@ void main() {
expect(findNativeBack(), findsOneWidget);
expect(find.byType(NavigationBar), findsNothing);
await tester.pageBack();
await tester.pumpAndSettle();
expect(
tester.widget<ListTile>(find.byKey(const Key('chat-row-a'))).selected,
isFalse,
);
await tester.pumpWidget(const SizedBox.shrink());
});
}
@@ -0,0 +1,113 @@
import 'dart:ui' show Tristate;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
import 'chat_test_harness.dart';
import 'fake_chat_gateway.dart';
void main() {
for (final cupertino in [false, true]) {
for (final brightness in Brightness.values) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} $brightness: active row '
'follows selection, survives refresh and clears with the route',
(tester) async {
final semantics = tester.ensureSemantics();
try {
final gateway = FakeChatGateway()
..sessionsReply = {
'chat_sessions': [
{'id': 'a', 'title': 'Same title'},
{'id': 'b', 'title': 'Same title'},
],
};
addTearDown(gateway.pushed.close);
final store = MemoryChatSessionLocalStore();
String? selected = 'a'; // A routed chat need not have been tapped.
late StateSetter rebuild;
final screen = StatefulBuilder(
builder: (context, setState) {
rebuild = setState;
return ChatSessionsScreen(
gateway: gateway,
localStore: store,
activeSessionId: selected,
onOpen: (session) => setState(() => selected = session['id']),
);
},
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
theme: CupertinoThemeData(brightness: brightness),
home: screen,
)
: MaterialApp(
theme: ThemeData(brightness: brightness),
home: screen,
),
);
await tester.pumpAndSettle();
void expectRow(String id, bool active) {
final row = find.byKey(Key('chat-row-$id'));
expect(
tester.getSemantics(row).flagsCollection.isSelected ==
Tristate.isTrue,
active,
);
if (cupertino) {
final tile = tester.widget<CupertinoListTile>(row);
expect(
tile.backgroundColor,
active
? CupertinoColors.tertiarySystemFill.resolveFrom(
tester.element(row),
)
: isNull,
);
} else {
final tile = tester.widget<ListTile>(row);
expect(tile.selected, active);
expect(
tile.selectedTileColor,
Theme.of(tester.element(row)).colorScheme.secondaryContainer,
);
}
}
expectRow('a', true);
expectRow('b', false);
await tester.tap(find.byKey(const Key('chat-row-b')));
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', true);
gateway.sessionsReply = {
'chat_sessions': [
{'id': 'b', 'title': 'Renamed active chat'},
{'id': 'a', 'title': 'Same title'},
],
};
await tester.tap(find.byKey(const Key('chat-refresh')));
await tester.pumpAndSettle();
expectRow('b', true);
expectRow('a', false);
rebuild(() => selected = null);
await tester.pumpAndSettle();
expectRow('a', false);
expectRow('b', false);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox.shrink());
} finally {
semantics.dispose();
}
},
);
}
}
}
+23 -1
View File
@@ -11,6 +11,8 @@ import { axNodes, enableSemantics, waitFor, capture } from './pipelines_probe_cd
const width = Number(process.env.PROBE_WIDTH ?? 1280);
const height = Number(process.env.PROBE_HEIGHT ?? 800);
const platform = process.env.PROBE_PLATFORM ?? 'cupertino';
const dark = process.env.PROBE_DARK === '1';
const messages = Array.from({ length: 6 }, (_, i) => ({
id: `m${i}`,
role: i % 2 ? 'assistant' : 'user',
@@ -21,18 +23,29 @@ await mkdir(output, { recursive: true });
const fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: messages });
const profile = await mkdtemp(join(tmpdir(), 'chat-list-detail-'));
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
const log = { width, height, checks: [], captures: [] };
const log = { width, height, platform, dark, checks: [], captures: [] };
let c;
const named = async (pattern) => (await axNodes(c)).filter(n => pattern.test(n.name?.value ?? ''));
const selectedChatRows = () => c.evaluate(`Array.from(document.querySelectorAll(
'[aria-current="true"], [aria-selected="true"]'
)).filter(e => (e.getAttribute('aria-label') || e.textContent || '').startsWith('Probe conversation')).length`);
try {
c = await connect((await waitForPage(await waitForPort(join(profile, 'DevToolsActivePort')))).webSocketDebuggerUrl);
await c.send('Page.enable');
if (platform === 'material') await c.send('Emulation.setUserAgentOverride', {
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36',
platform: 'Win32',
});
await c.send('Emulation.setEmulatedMedia', {
features: [{ name: 'prefers-color-scheme', value: dark ? 'dark' : 'light' }],
});
await c.send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false });
await c.send('Page.navigate', { url: fixture.url + '/chat' });
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000));
await enableSemantics(c);
assert.ok(await waitFor(async () => (await named(/Select a chat/)).length > 0, 30000), 'empty detail pane');
log.checks.push('empty pane beside list');
assert.equal(await selectedChatRows(), 0, 'no chat selected initially');
await sleep(500);
await capture(c, output, log, 'list-empty-pane');
@@ -42,6 +55,7 @@ try {
const [x1, y1, , , x3, y3] = model.content;
await c.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: (x1 + x3) / 2, y: (y1 + y3) / 2, button: 'left', clickCount: 1 });
await c.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: (x1 + x3) / 2, y: (y1 + y3) / 2, button: 'left', clickCount: 1 });
await c.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: width - 5, y: height - 5 });
assert.ok(await waitFor(async () => (await named(/Recorded fixture message 5/)).length > 0, 30000), 'open chat transcript');
await sleep(800);
// The rail, the list and the open chat are all on screen; nothing offers Back.
@@ -52,7 +66,15 @@ try {
assert.equal((await named(/^Back(\s|$)/)).length, 0, 'no Back in the two-pane layout');
log.path = await c.evaluate('location.pathname');
log.checks.push('rail, list and open chat visible together; no Back');
assert.equal(await selectedChatRows(), 1, 'open chat row stays selected after the pointer leaves');
log.checks.push('active chat row exposes persistent selected semantics');
await capture(c, output, log, 'list-open-chat');
await c.send('Page.reload');
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000));
await enableSemantics(c);
assert.ok(await waitFor(async () => (await named(/Recorded fixture message 5/)).length > 0, 30000), 'deep-linked chat reloads');
assert.ok(await waitFor(async () => await selectedChatRows() === 1, 30000), 'routed chat remains selected after reload');
log.checks.push('deep-linked chat selection survives reload');
console.log(JSON.stringify(log, null, 2));
} catch (error) {
if (c) {