Skip to content

Commit c882109

Browse files
authored
[Property Editor] Miscellaneous small polish items (#9055)
1 parent 8857bd4 commit c882109

3 files changed

Lines changed: 156 additions & 131 deletions

File tree

packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/property_editor_view.dart

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class _NoEditablePropertiesMessage extends StatelessWidget {
315315
' has no editable widget properties.\n\nThe Flutter Property Editor currently supports editing properties of type ',
316316
style: theme.regularTextStyle,
317317
),
318-
TextSpan(text: 'string', style: fixedFontStyle),
318+
TextSpan(text: 'String', style: fixedFontStyle),
319319
const TextSpan(text: ', '),
320320
TextSpan(text: 'int', style: fixedFontStyle),
321321
const TextSpan(text: ', '),
@@ -348,31 +348,34 @@ class _WidgetNameAndDocumentation extends StatelessWidget {
348348

349349
@override
350350
Widget build(BuildContext context) {
351-
return Column(
352-
mainAxisSize: MainAxisSize.min,
353-
children: [
354-
Padding(
355-
padding: const EdgeInsets.only(bottom: denseSpacing),
356-
child: Text(
357-
name,
358-
style: Theme.of(context).fixedFontStyle.copyWith(
359-
fontWeight: FontWeight.bold,
360-
fontSize: defaultFontSize + 1,
351+
return SelectionArea(
352+
child: Column(
353+
mainAxisSize: MainAxisSize.min,
354+
children: [
355+
Container(
356+
alignment: Alignment.centerLeft,
357+
padding: const EdgeInsets.only(bottom: denseSpacing),
358+
child: Text(
359+
name,
360+
style: Theme.of(context).fixedFontStyle.copyWith(
361+
fontWeight: FontWeight.bold,
362+
fontSize: defaultFontSize + 1,
363+
),
361364
),
362365
),
363-
),
364-
Row(
365-
children: [
366-
Expanded(
367-
child: _ExpandableWidgetDocumentation(
368-
documentation:
369-
documentation ?? 'Creates ${addIndefiniteArticle(name)}.',
366+
Row(
367+
children: [
368+
Expanded(
369+
child: _ExpandableWidgetDocumentation(
370+
documentation:
371+
documentation ?? 'Creates ${addIndefiniteArticle(name)}.',
372+
),
370373
),
371-
),
372-
],
373-
),
374-
const PaddedDivider.noPadding(),
375-
],
374+
],
375+
),
376+
const PaddedDivider.noPadding(),
377+
],
378+
),
376379
);
377380
}
378381
}
@@ -417,8 +420,7 @@ class _ExpandableWidgetDocumentationState
417420
final paragraphs = widget.documentation.split('\n');
418421

419422
if (paragraphs.length == 1) {
420-
return convertDartDocToRichText(
421-
widget.documentation,
423+
return DartDocConverter(widget.documentation).toText(
422424
regularFontStyle: regularFontStyle,
423425
fixedFontStyle: fixedFontStyle,
424426
);
@@ -433,16 +435,14 @@ class _ExpandableWidgetDocumentationState
433435
// or collapses the text block. Because the Dart doc is never very
434436
// large, this is not an expensive operation. However, we could
435437
// consider caching the result if this needs to be optimized.
436-
convertDartDocToRichText(
437-
firstParagraph,
438+
DartDocConverter(firstParagraph).toText(
438439
regularFontStyle: regularFontStyle,
439440
fixedFontStyle: fixedFontStyle,
440441
),
441442
if (_isExpanded)
442443
FadeTransition(
443444
opacity: _expandAnimation,
444-
child: convertDartDocToRichText(
445-
otherParagraphs.join('\n'),
445+
child: DartDocConverter(otherParagraphs.join('\n')).toText(
446446
regularFontStyle: regularFontStyle,
447447
fixedFontStyle: fixedFontStyle,
448448
),

packages/devtools_app/lib/src/standalone_ui/ide_shared/property_editor/utils/utils.dart

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,94 @@
55
import 'package:flutter/widgets.dart';
66
import '_utils_desktop.dart' if (dart.library.js_interop) '_utils_web.dart';
77

8-
/// Converts a [dartDocText] String into a [RichText] widget.
9-
///
10-
/// Removes any brackets and backticks and displays the text inside them as
11-
/// fixed font.
12-
RichText convertDartDocToRichText(
13-
String dartDocText, {
14-
required TextStyle regularFontStyle,
15-
required TextStyle fixedFontStyle,
16-
}) {
17-
final children = <TextSpan>[];
18-
int currentIndex = 0;
8+
/// Converts a [dartDocText] String into a [Text] widget.
9+
class DartDocConverter {
10+
DartDocConverter(this.dartDocText);
1911

20-
while (currentIndex < dartDocText.length) {
21-
final openBracketIndex = dartDocText.indexOf('[', currentIndex);
22-
final openBacktickIndex = dartDocText.indexOf('`', currentIndex);
12+
final String dartDocText;
2313

24-
int nextSpecialCharIndex = -1;
25-
bool isLink = false;
14+
/// Converts the [dartDocText] String into a [Text] widget.
15+
///
16+
/// Removes any brackets and backticks and displays the text inside them with
17+
/// [fixedFontStyle]. All other text uses [regularFontStyle].
18+
Text toText({
19+
required TextStyle regularFontStyle,
20+
required TextStyle fixedFontStyle,
21+
}) {
22+
final children = toTextSpans(
23+
regularFontStyle: regularFontStyle,
24+
fixedFontStyle: fixedFontStyle,
25+
);
26+
return Text.rich(TextSpan(children: children));
27+
}
2628

27-
if (openBracketIndex != -1 &&
28-
(openBacktickIndex == -1 || openBracketIndex < openBacktickIndex)) {
29-
nextSpecialCharIndex = openBracketIndex;
30-
isLink = true;
31-
} else if (openBacktickIndex != -1 &&
32-
(openBracketIndex == -1 || openBacktickIndex < openBracketIndex)) {
33-
nextSpecialCharIndex = openBacktickIndex;
34-
}
29+
@visibleForTesting
30+
List<TextSpan> toTextSpans({
31+
required TextStyle regularFontStyle,
32+
required TextStyle fixedFontStyle,
33+
}) {
34+
final children = <TextSpan>[];
35+
int currentIndex = 0;
3536

36-
if (nextSpecialCharIndex == -1) {
37-
// No more special characters, add the remaining text.
38-
children.add(
39-
TextSpan(
40-
text: dartDocText.substring(currentIndex),
41-
style: regularFontStyle,
42-
),
43-
);
44-
break;
45-
}
37+
while (currentIndex < dartDocText.length) {
38+
final openBracketIndex = dartDocText.indexOf('[', currentIndex);
39+
final openBacktickIndex = dartDocText.indexOf('`', currentIndex);
4640

47-
// Add text before the special character.
48-
children.add(
49-
TextSpan(
50-
text: dartDocText.substring(currentIndex, nextSpecialCharIndex),
51-
style: regularFontStyle,
52-
),
53-
);
41+
int nextSpecialCharIndex = -1;
42+
bool isLink = false;
5443

55-
final closeIndex = dartDocText.indexOf(
56-
isLink ? ']' : '`',
57-
isLink ? nextSpecialCharIndex : nextSpecialCharIndex + 1,
58-
);
59-
if (closeIndex == -1) {
60-
// Treat unmatched brackets/backticks as regular text.
44+
if (openBracketIndex != -1 &&
45+
(openBacktickIndex == -1 || openBracketIndex < openBacktickIndex)) {
46+
nextSpecialCharIndex = openBracketIndex;
47+
isLink = true;
48+
} else if (openBacktickIndex != -1 &&
49+
(openBracketIndex == -1 || openBacktickIndex < openBracketIndex)) {
50+
nextSpecialCharIndex = openBacktickIndex;
51+
}
52+
53+
if (nextSpecialCharIndex == -1) {
54+
// No more special characters, add the remaining text.
55+
children.add(
56+
TextSpan(
57+
text: dartDocText.substring(currentIndex),
58+
style: regularFontStyle,
59+
),
60+
);
61+
break;
62+
}
63+
64+
// Add text before the special character.
6165
children.add(
6266
TextSpan(
63-
text: dartDocText.substring(nextSpecialCharIndex),
67+
text: dartDocText.substring(currentIndex, nextSpecialCharIndex),
6468
style: regularFontStyle,
6569
),
6670
);
67-
currentIndex = dartDocText.length; // Effectively break the loop.
68-
} else {
69-
final content = dartDocText.substring(
70-
nextSpecialCharIndex + 1,
71-
closeIndex,
71+
72+
final closeIndex = dartDocText.indexOf(
73+
isLink ? ']' : '`',
74+
isLink ? nextSpecialCharIndex : nextSpecialCharIndex + 1,
7275
);
73-
children.add(TextSpan(text: content, style: fixedFontStyle));
74-
currentIndex = closeIndex + 1;
76+
if (closeIndex == -1) {
77+
// Treat unmatched brackets/backticks as regular text.
78+
children.add(
79+
TextSpan(
80+
text: dartDocText.substring(nextSpecialCharIndex),
81+
style: regularFontStyle,
82+
),
83+
);
84+
currentIndex = dartDocText.length; // Effectively break the loop.
85+
} else {
86+
final content = dartDocText.substring(
87+
nextSpecialCharIndex + 1,
88+
closeIndex,
89+
);
90+
children.add(TextSpan(text: content, style: fixedFontStyle));
91+
currentIndex = closeIndex + 1;
92+
}
7593
}
94+
return children;
7695
}
77-
78-
return RichText(text: TextSpan(children: children));
7996
}
8097

8198
/// Workaround to force reload the Property Editor when it disconnects.

0 commit comments

Comments
 (0)