alexeyinkin commented on code in PR #24865:
URL: https://github.com/apache/beam/pull/24865#discussion_r1063221708


##########
playground/frontend/playground_components/lib/src/controllers/snippet_editing_controller.dart:
##########
@@ -186,39 +128,84 @@ class SnippetEditingController extends ChangeNotifier {
 
     return ContentExampleLoadingDescriptor(
       complexity: example.complexity,
-      content: codeController.fullText,
+      files: getFiles(),
       name: example.name,
       sdk: sdk,
     );
   }
 
-  void setSource(String source) {
-    codeController.readOnlySectionNames = const {};
-    codeController.visibleSectionNames = const {};
+  void _replaceFileControllers(
+    Iterable<SnippetFile> files,
+    ExampleViewOptions viewOptions,
+  ) {
+    for (final oldController in fileControllers) {
+      oldController.removeListener(_onFileControllerChanged);
+    }
+    final newControllers = <SnippetFileEditingController>[];
+
+    for (final file in files) {
+      final controller = SnippetFileEditingController(
+        contextLine1Based: file.isMain ? _selectedExample?.contextLine : null,
+        savedFile: file,
+        sdk: sdk,
+        viewOptions: viewOptions,
+      );
+
+      newControllers.add(controller);
+      controller.addListener(_onFileControllerChanged);
+    }
 
-    codeController.fullText = source;
-    codeController.historyController.deleteHistory();
-  }
+    for (final oldController in fileControllers) {
+      oldController.dispose();
+    }
 
-  void _onSymbolsNotifierChanged() {
-    final mode = sdk.highlightMode;
-    if (mode == null) {
-      return;
+    fileControllers.clear();
+    fileControllers.addAll(newControllers);
+
+    _fileControllersByName.clear();
+    for (final controller in newControllers) {
+      _fileControllersByName[controller.savedFile.name] = controller;
     }
 
-    final dictionary = _symbolsNotifier.getDictionary(mode);
-    if (dictionary == null) {
-      return;
+    _activeFileController =
+        fileControllers.firstWhereOrNull((c) => c.savedFile.isMain);
+  }
+
+  void _onFileControllerChanged() {
+    if (!_isChanged) {
+      if (_isAnyFileControllerChanged()) {
+        _isChanged = true;
+        notifyListeners();
+      }
+    } else {
+      _updateIsChanged();
+      if (!_isChanged) {
+        notifyListeners();
+      }
     }
+  }
 
-    codeController.autocompleter.setCustomWords(dictionary.symbols);
+  bool _isAnyFileControllerChanged() {
+    return fileControllers.any((c) => c.isChanged);
   }
 
-  @override
-  void dispose() {
-    _symbolsNotifier.removeListener(
-      _onSymbolsNotifierChanged,
-    );
-    super.dispose();
+  SnippetFileEditingController? get activeFileController =>
+      _activeFileController;
+
+  SnippetFileEditingController? getFileControllerByName(String name) {
+    return _fileControllersByName[name];
+  }
+
+  void activateFileControllerByName(String name) {
+    final newController = getFileControllerByName(name);

Review Comment:
   Yes, this case is valid and handled. Added a test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to