KonradJanica commented on a change in pull request #16892:
URL: https://github.com/apache/beam/pull/16892#discussion_r812419199



##########
File path: 
playground/frontend/lib/modules/editor/components/editor_textarea.dart
##########
@@ -133,44 +133,78 @@ class _EditorTextAreaState extends State<EditorTextArea> {
     focusNode.requestFocus();
     if (_codeController!.text.isNotEmpty) {
       _codeController!.selection = TextSelection.fromPosition(
-        TextPosition(offset: _findOffset()),
+        TextPosition(
+          offset: _getOffset(),
+        ),
       );
     }
   }
 
-  _findOffset() {
+  int _getOffset() {
+    int contextLine = _getIndexOfContextLine();
+    String pattern = _getPattern(_getQntOfStringsOnScreen());
+
+    if (pattern == '' || pattern == '}') {
+      return _codeController!.text.lastIndexOf(pattern);
+    }
+
     return _codeController!.text.indexOf(
-      _skipStrings(kNumberOfStringsToSkip),
-      _getPositionAfterImportsAndLicenses(widget.sdk),
+      pattern,
+      contextLine,
     );
   }
 
-  String _skipStrings(int qntOfStrings) {
-    List<String> strings = _codeController!.text
-        .substring(_getPositionAfterImportsAndLicenses(widget.sdk))
-        .split('\n');
+  String _getPattern(int qntOfStrings) {
+    int contextLineIndex = _getIndexOfContextLine();
+    List<String> stringsAfterContextLine =
+        _codeController!.text.substring(contextLineIndex).split('\n');
+
     String result =
-        strings.length > qntOfStrings ? strings[qntOfStrings] : strings.last;
-    if (result == '') {
-      return _skipStrings(qntOfStrings - 1);
-    } else {
-      return result;
+        stringsAfterContextLine.length + kAdditionalLinesForScrolling >
+                qntOfStrings
+            ? _getResultSubstring(stringsAfterContextLine, qntOfStrings)
+            : stringsAfterContextLine.last;
+
+    return result;
+  }
+
+  int _getQntOfStringsOnScreen() {
+    RenderBox? rBox =

Review comment:
       Is the question mark necessary here? It seems like rBox.size.height 
cannot be null.




-- 
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