模组管理支持搜索根据更多数据搜索内容 (#3230)

Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
Zkitefly
2025-08-06 21:02:36 +08:00
committed by GitHub
parent f95ebe2224
commit ac4c3a7501

View File

@@ -62,6 +62,7 @@ import org.jackhuang.hmcl.util.io.CompressingUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.io.NetworkUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.file.FileSystem;
import java.nio.file.Files;
@@ -248,23 +249,30 @@ class ModListPageSkin extends SkinBase<ModListPage> {
} else {
listView.getItems().clear();
Predicate<String> predicate;
Predicate<@Nullable String> predicate;
if (queryString.startsWith("regex:")) {
try {
Pattern pattern = Pattern.compile(queryString.substring("regex:".length()));
predicate = s -> pattern.matcher(s).find();
predicate = s -> s != null && pattern.matcher(s).find();
} catch (Throwable e) {
LOG.warning("Illegal regular expression", e);
return;
}
} else {
String lowerQueryString = queryString.toLowerCase(Locale.ROOT);
predicate = s -> s.toLowerCase(Locale.ROOT).contains(lowerQueryString);
predicate = s -> s != null && s.toLowerCase(Locale.ROOT).contains(lowerQueryString);
}
// Do we need to search in the background thread?
for (ModInfoObject item : getSkinnable().getItems()) {
if (predicate.test(item.getModInfo().getFileName())) {
LocalModFile modInfo = item.getModInfo();
if (predicate.test(modInfo.getFileName())
|| predicate.test(modInfo.getName())
|| predicate.test(modInfo.getVersion())
|| predicate.test(modInfo.getGameVersion())
|| predicate.test(modInfo.getId())
|| predicate.test(Objects.toString(modInfo.getModLoaderType()))
|| predicate.test((item.getMod() != null ? item.getMod().getDisplayName() : null))) {
listView.getItems().add(item);
}
}