mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-12 00:17:51 +00:00
Add Space Mode Settings to Search (#571)
Co-authored-by: slprime <history-21@yandex.ru> Co-authored-by: boubou19 <miisterunknown@gmail.com>
This commit is contained in:
6 files changed
+160
-65
No files matched your search
@@ -1,12 +1,12 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.nei.FormattedTextField.TextFormatter;
|
||||
import codechicken.nei.SearchTokenParser.SearchToken;
|
||||
|
||||
public class SearchTextFormatter implements TextFormatter {
|
||||
|
||||
@@ -17,63 +17,50 @@ public class SearchTextFormatter implements TextFormatter {
|
||||
}
|
||||
|
||||
public String format(String text) {
|
||||
final String[] parts = text.split("\\|");
|
||||
final Pattern splitPattern = searchParser.getSplitPattern();
|
||||
final String[] parts = (text + "| ").split("\\|");
|
||||
StringJoiner formattedText = new StringJoiner(EnumChatFormatting.GRAY + "|");
|
||||
|
||||
for (String filterText : parts) {
|
||||
Matcher filterMatcher = splitPattern.matcher(filterText);
|
||||
for (int i = 0; i < parts.length - 1; i++) {
|
||||
final String filterText = parts[i];
|
||||
final List<SearchToken> tokens = searchParser.splitSearchText(filterText);
|
||||
StringBuilder formattedPart = new StringBuilder();
|
||||
int startIndex = 0;
|
||||
|
||||
while (filterMatcher.find()) {
|
||||
boolean ignore = "-".equals(filterMatcher.group(2));
|
||||
String firstChar = filterMatcher.group(3);
|
||||
String token = filterMatcher.group(4);
|
||||
boolean quotes = token.length() > 1 && token.startsWith("\"") && token.endsWith("\"");
|
||||
|
||||
if (quotes) {
|
||||
token = token.substring(1, token.length() - 1);
|
||||
}
|
||||
|
||||
formattedPart.append(filterText.substring(startIndex, filterMatcher.start()));
|
||||
for (SearchToken token : tokens) {
|
||||
formattedPart.append(filterText.substring(startIndex, token.start));
|
||||
EnumChatFormatting tokenColor = EnumChatFormatting.RESET;
|
||||
|
||||
if (!firstChar.isEmpty()) {
|
||||
tokenColor = searchParser.getProvider(firstChar.charAt(0)).getHighlightedColor();
|
||||
if (token.firstChar != null) {
|
||||
tokenColor = searchParser.getProvider(token.firstChar).getHighlightedColor();
|
||||
}
|
||||
|
||||
if (ignore) {
|
||||
if (token.ignore) {
|
||||
formattedPart.append(EnumChatFormatting.BLUE + "-");
|
||||
}
|
||||
|
||||
if (!firstChar.isEmpty()) {
|
||||
formattedPart.append(tokenColor + firstChar);
|
||||
if (token.firstChar != null) {
|
||||
formattedPart.append(tokenColor + String.valueOf(token.firstChar));
|
||||
}
|
||||
|
||||
if (quotes) {
|
||||
if (token.quotes) {
|
||||
formattedPart.append(EnumChatFormatting.GOLD + "\"");
|
||||
}
|
||||
|
||||
if (!token.isEmpty()) {
|
||||
formattedPart.append(tokenColor + token);
|
||||
if (!token.rawText.isEmpty()) {
|
||||
formattedPart.append(tokenColor + token.rawText);
|
||||
}
|
||||
|
||||
if (quotes) {
|
||||
if (token.quotes) {
|
||||
formattedPart.append(EnumChatFormatting.GOLD + "\"");
|
||||
}
|
||||
|
||||
startIndex = filterMatcher.end();
|
||||
startIndex = token.end;
|
||||
}
|
||||
|
||||
formattedPart.append(filterText.substring(startIndex, filterText.length()));
|
||||
formattedText.add(formattedPart);
|
||||
}
|
||||
|
||||
if (text.endsWith("|")) {
|
||||
formattedText.add("");
|
||||
}
|
||||
|
||||
return formattedText.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user