Skip to content

Commit

Permalink
fix(gui): don't highlight whitespaces and special symbols (#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Mar 28, 2022
1 parent e5fa818 commit e4f4c1b
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions jadx-gui/src/main/java/jadx/gui/ui/codearea/AbstractCodeArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
import org.fife.ui.rsyntaxtextarea.TokenTypes;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -196,13 +197,37 @@ public String getWordUnderCaret() {
public String getWordByPosition(int pos) {
try {
Token token = modelToToken(pos);
if (token != null) {
return token.getLexeme();
}
return getWordFromToken(token);
} catch (Exception e) {
LOG.error("Failed to get word at pos: {}", pos, e);
return null;
}
}

@Nullable
private static String getWordFromToken(@Nullable Token token) {
if (token == null) {
return null;
}
switch (token.getType()) {
case TokenTypes.NULL:
case TokenTypes.WHITESPACE:
case TokenTypes.SEPARATOR:
case TokenTypes.OPERATOR:
return null;

case TokenTypes.IDENTIFIER:
if (token.length() == 1) {
char ch = token.charAt(0);
if (ch == ';' || ch == '.') {
return null;
}
}
return token.getLexeme();

default:
return token.getLexeme();
}
return null;
}

/**
Expand Down

0 comments on commit e4f4c1b

Please sign in to comment.