miamihotline commented on a change in pull request #16892:
URL: https://github.com/apache/beam/pull/16892#discussion_r813813220
##########
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 =
+ codeFieldKey.currentContext?.findRenderObject() as RenderBox;
+ double height = rBox.size.height * .75;
+
+ return height ~/ kCodeFontSize;
+ }
+
+ int _getIndexOfContextLine() {
+ int ctxLineNumber = widget.example!.contextLine;
+ String contextLine = _codeController!.text.split('\n')[ctxLineNumber];
+
+ while (contextLine == '') {
+ ctxLineNumber -= 1;
+ contextLine = _codeController!.text.split('\n')[ctxLineNumber];
}
+
+ return _codeController!.text.indexOf(contextLine);
}
- int _getPositionAfterImportsAndLicenses(SDK sdk) {
- switch (sdk) {
- case SDK.java:
- return _codeController!.text.lastIndexOf(RegExp(kJavaRegExp));
- case SDK.python:
- return _codeController!.text.lastIndexOf(RegExp(kPythonRegExp));
- case SDK.go:
- return _codeController!.text.lastIndexOf(RegExp(kGoRegExp));
- case SDK.scio:
- return _codeController!.text.indexOf(
- _codeController!.text.split('\n')[0],
- );
+ // This function made for more accuracy in the process of finding an exact
line.
+ String _getResultSubstring(
+ List<String> stringsAfterContextLine,
+ int qntOfStrings,
+ ) {
+ String result = '';
Review comment:
Hello, @KonradJanica! Thank you for the review, I'll change that.
--
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]