You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/06/12 08:55:55 UTC
[groovy] branch master updated: GROOVY-10134: Groovy console can
not highlight token properly sometimes
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 73e6c82 GROOVY-10134: Groovy console can not highlight token properly sometimes
73e6c82 is described below
commit 73e6c821d71ccc641b233a643f5b19186f914e96
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jun 12 15:48:16 2021 +0800
GROOVY-10134: Groovy console can not highlight token properly sometimes
---
.../console/ui/text/SmartDocumentFilter.java | 23 +++++++++++-----------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
index 9b103e6..904ce90 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
@@ -29,6 +29,7 @@ import org.apache.groovy.parser.antlr4.GroovyLangLexer;
import org.apache.groovy.parser.antlr4.GroovySyntaxError;
import org.apache.groovy.parser.antlr4.util.PositionConfigureUtils;
import org.apache.groovy.parser.antlr4.util.StringUtils;
+import org.apache.groovy.util.ReversedList;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
@@ -40,7 +41,6 @@ import javax.swing.text.StyleContext;
import java.awt.Color;
import java.io.IOException;
import java.io.StringReader;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -256,13 +256,13 @@ public class SmartDocumentFilter extends DocumentFilter {
}
List<Token> tmpTokenList = filterNewlines(tokenList);
- int tokenListSize = tmpTokenList.size();
- if (0 == tokenListSize) {
+ int tmpTokenListSize = tmpTokenList.size();
+ if (0 == tmpTokenListSize) {
return tokenList;
}
int startTokenIndex = 0;
- int minSize = Math.min(tokenListSize, latestTokenListSize);
+ int minSize = Math.min(tmpTokenListSize, latestTokenListSize);
for (int i = 0; i < minSize; i++) {
Token token = tmpTokenList.get(i);
Token latestToken = tmpLatestTokenList.get(i);
@@ -277,13 +277,10 @@ public class SmartDocumentFilter extends DocumentFilter {
break;
}
- List<Token> newTokenList = new ArrayList<>(tmpTokenList);
- List<Token> newLatestTokenList = new ArrayList<>(tmpLatestTokenList);
+ List<Token> newTokenList = new ReversedList<>(tmpTokenList);
+ List<Token> newLatestTokenList = new ReversedList<>(tmpLatestTokenList);
- Collections.reverse(newTokenList);
- Collections.reverse(newLatestTokenList);
-
- int stopTokenIndex = tokenListSize;
+ int stopTokenIndex = tmpTokenListSize;
Token lastToken = newTokenList.get(0);
Token lastLatestToken = newLatestTokenList.get(0);
@@ -298,11 +295,13 @@ public class SmartDocumentFilter extends DocumentFilter {
continue;
}
- stopTokenIndex = tokenListSize - i;
+ stopTokenIndex = tmpTokenListSize - i;
break;
}
- if (startTokenIndex <= stopTokenIndex) {
+ if (startTokenIndex == stopTokenIndex) {
+ return tmpTokenListSize != latestTokenListSize ? tokenList : Collections.emptyList();
+ } else if (startTokenIndex < stopTokenIndex) {
return tmpTokenList.subList(startTokenIndex, stopTokenIndex);
}