Skip to content

Commit 3e4d5a7

Browse files
committed
Fix long string overlay in debugger Variables panel (#7112)
1 parent 4f6a8e8 commit 3e4d5a7

2 files changed

Lines changed: 67 additions & 16 deletions

File tree

packages/devtools_app/lib/src/shared/console/widgets/display_provider.dart

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ class _DisplayProviderState extends State<DisplayProvider> {
4646
return InteractivityWrapper(
4747
onTap: widget.onTap,
4848
menuButtons: _getMenuButtons(context),
49-
child: Text.rich(
50-
TextSpan(
51-
children: textSpansFromAnsi(
52-
widget.variable.text!,
53-
theme.subtleFixedFontStyle,
49+
child: DevToolsTooltip(
50+
message: widget.variable.text,
51+
child: Text.rich(
52+
maxLines: 1,
53+
softWrap: false,
54+
overflow: TextOverflow.ellipsis,
55+
TextSpan(
56+
children: textSpansFromAnsi(
57+
widget.variable.text!,
58+
theme.subtleFixedFontStyle,
59+
),
5460
),
5561
),
5662
),
@@ -88,6 +94,7 @@ class _DisplayProviderState extends State<DisplayProvider> {
8894
Expanded(
8995
child: Text.rich(
9096
maxLines: 1,
97+
softWrap: false,
9198
overflow: TextOverflow.ellipsis,
9299
TextSpan(
93100
text: hasName ? widget.variable.name : null,
@@ -248,18 +255,27 @@ class DapDisplayProvider extends StatelessWidget {
248255
// TODO(https://github.com/flutter/devtools/issues/6056): Wrap in
249256
// interactivity wrapper to provide inspect and re-root functionality. Add
250257
// tooltip on hover to provide type information.
251-
return Text.rich(
252-
TextSpan(
253-
text: name,
254-
style: theme.fixedFontStyle.apply(
255-
color: theme.colorScheme.controlFlowSyntaxColor,
258+
return DevToolsTooltip(
259+
message: value,
260+
child: Text.rich(
261+
maxLines: 1,
262+
softWrap: false,
263+
overflow: TextOverflow.ellipsis,
264+
TextSpan(
265+
text: name,
266+
style: theme.fixedFontStyle.apply(
267+
color: theme.colorScheme.controlFlowSyntaxColor,
268+
),
269+
children: [
270+
TextSpan(text: ': ', style: theme.fixedFontStyle),
271+
// TODO(https://github.com/flutter/devtools/issues/6056): Change text
272+
// style based on variable type.
273+
TextSpan(
274+
text: value.replaceAll('\n', '\\n'),
275+
style: theme.subtleFixedFontStyle,
276+
),
277+
],
256278
),
257-
children: [
258-
TextSpan(text: ': ', style: theme.fixedFontStyle),
259-
// TODO(https://github.com/flutter/devtools/issues/6056): Change text
260-
// style based on variable type.
261-
TextSpan(text: value, style: theme.subtleFixedFontStyle),
262-
],
263279
),
264280
);
265281
}

packages/devtools_app/test/screens/debugger/debugger_screen_dap_variables_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,39 @@ void main() {
126126
// String is now visible.
127127
expect(stringFinder, findsOneWidget);
128128
});
129+
testWidgetsWithWindowSize(
130+
'Truncates long variables to a single line with tooltip',
131+
windowSize,
132+
(WidgetTester tester) async {
133+
final longString = 'a' * 1000;
134+
final node = DapObjectNode(
135+
service: vmService,
136+
variable: dap.Variable(
137+
name: 'longVar',
138+
value: longString,
139+
variablesReference: 0,
140+
),
141+
);
142+
143+
fakeServiceConnection.appState.setDapVariables([node]);
144+
await pumpDebuggerScreen(tester, debuggerController);
145+
146+
final tooltipFinder = find.byWidgetPredicate(
147+
(widget) => widget is DevToolsTooltip && widget.message == longString,
148+
);
149+
expect(tooltipFinder, findsOneWidget);
150+
151+
final finder = find.byType(RichText);
152+
bool foundTruncated = false;
153+
for (final widget in tester.widgetList<RichText>(finder)) {
154+
if (widget.text.toPlainText().contains('longVar: $longString')) {
155+
expect(widget.maxLines, 1);
156+
expect(widget.softWrap, false);
157+
expect(widget.overflow, TextOverflow.ellipsis);
158+
foundTruncated = true;
159+
}
160+
}
161+
expect(foundTruncated, isTrue);
162+
},
163+
);
129164
}

0 commit comments

Comments
 (0)