Skip to content

Commit 657f00f

Browse files
authored
[Property Editor] Do not trigger edits if there have been no changes to a property (#8951)
1 parent 37aa311 commit 657f00f

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ class _TextInputState<T> extends State<_TextInput<T>>
214214
@override
215215
void initState() {
216216
super.initState();
217+
_currentValue = widget.property.valueDisplay;
217218
_focusNode = FocusNode(debugLabel: 'text-input-${widget.property.name}');
218219

219220
addAutoDisposeListener(_focusNode, () async {
@@ -270,6 +271,9 @@ mixin _PropertyInputMixin<T extends StatefulWidget, U> on State<T> {
270271
required EditArgumentFunction editPropertyCallback,
271272
required String? valueAsString,
272273
}) async {
274+
// If no changes have been made to the property, don't send an edit request.
275+
if (property.valueDisplay == valueAsString) return;
276+
273277
clearServerError();
274278
final argName = property.name;
275279
ga.select(

packages/devtools_app/test/standalone_ui/ide_shared/property_editor/property_editor_test.dart

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,30 @@ void main() {
417417
});
418418
});
419419

420+
testWidgets('editing a string input to its current value (title)', (
421+
tester,
422+
) async {
423+
return await tester.runAsync(() async {
424+
// Load the property editor.
425+
controller.initForTestsOnly(editableArgsResult: result1);
426+
await tester.pumpWidget(wrap(propertyEditor));
427+
428+
// Edit the title.
429+
final titleInput = _findTextFormField('title');
430+
await _inputText(titleInput, text: 'Hello world!', tester: tester);
431+
432+
// Verify it doesn't trigger an edit.
433+
try {
434+
await nextEditCompleter.future.timeout(
435+
const Duration(milliseconds: 100),
436+
);
437+
fail('nextEditCompleter was unexpectedly completed.');
438+
} on TimeoutException catch (e) {
439+
expect(e, isA<TimeoutException>());
440+
}
441+
});
442+
});
443+
420444
testWidgets('submitting a string input with TAB (title)', (tester) async {
421445
return await tester.runAsync(() async {
422446
// Load the property editor.
@@ -474,6 +498,30 @@ void main() {
474498
});
475499
});
476500

501+
testWidgets('editing a numeric input to its default value (height)', (
502+
tester,
503+
) async {
504+
return await tester.runAsync(() async {
505+
// Load the property editor.
506+
controller.initForTestsOnly(editableArgsResult: result1);
507+
await tester.pumpWidget(wrap(propertyEditor));
508+
509+
// Edit the height.
510+
final heightInput = _findTextFormField('height');
511+
await _inputText(heightInput, text: '20.0', tester: tester);
512+
513+
// Verify it doesn't trigger an edit.
514+
try {
515+
await nextEditCompleter.future.timeout(
516+
const Duration(milliseconds: 100),
517+
);
518+
fail('nextEditCompleter was unexpectedly completed.');
519+
} on TimeoutException catch (e) {
520+
expect(e, isA<TimeoutException>());
521+
}
522+
});
523+
});
524+
477525
testWidgets('submitting a numeric input with TAB (height)', (tester) async {
478526
return await tester.runAsync(() async {
479527
// Load the property editor.

0 commit comments

Comments
 (0)