Skip to content

Commit 1778e9d

Browse files
authored
fix: select logs outside the screen was not deselected correctly (#5955)
Fix #5884
1 parent dbb63e9 commit 1778e9d

2 files changed

Lines changed: 6 additions & 44 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/game/Log.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public static int getLogLines() {
3131

3232
private final String log;
3333
private Log4jLevel level;
34-
private boolean selected = false;
3534

3635
public Log(String log) {
3736
this.log = log;
@@ -57,14 +56,6 @@ public Log4jLevel getLevel() {
5756
return level;
5857
}
5958

60-
public boolean isSelected() {
61-
return selected;
62-
}
63-
64-
public void setSelected(boolean selected) {
65-
this.selected = selected;
66-
}
67-
6859
@Override
6960
public String toString() {
7061
return log;

HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import javafx.scene.Scene;
3131
import javafx.scene.control.*;
3232
import javafx.scene.input.KeyCode;
33-
import javafx.scene.input.MouseButton;
3433
import javafx.scene.layout.*;
3534
import javafx.stage.Stage;
3635
import org.jackhuang.hmcl.game.GameDumpGenerator;
@@ -39,7 +38,6 @@
3938
import org.jackhuang.hmcl.task.Schedulers;
4039
import org.jackhuang.hmcl.theme.Themes;
4140
import org.jackhuang.hmcl.ui.construct.MessageDialogPane;
42-
import org.jackhuang.hmcl.ui.construct.NoneMultipleSelectionModel;
4341
import org.jackhuang.hmcl.ui.construct.SpinnerPane;
4442
import org.jackhuang.hmcl.util.CircularArrayList;
4543
import org.jackhuang.hmcl.util.Lang;
@@ -261,9 +259,6 @@ private static final class LogWindowSkin extends SkinBase<LogWindowImpl> {
261259
private static final PseudoClass INFO = PseudoClass.getPseudoClass("info");
262260
private static final PseudoClass DEBUG = PseudoClass.getPseudoClass("debug");
263261
private static final PseudoClass TRACE = PseudoClass.getPseudoClass("trace");
264-
private static final PseudoClass SELECTED = PseudoClass.getPseudoClass("selected");
265-
266-
private final Set<ListCell<Log>> selected = new HashSet<>();
267262
private final JFXSnackbar snackbar = new JFXSnackbar();
268263

269264
LogWindowSkin(LogWindowImpl control) {
@@ -309,6 +304,7 @@ private static final class LogWindowSkin extends SkinBase<LogWindowImpl> {
309304

310305
{
311306
ListView<Log> listView = control.listView;
307+
listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
312308
listView.getItems().addListener((InvalidationListener) observable -> {
313309
if (!listView.getItems().isEmpty() && control.autoScroll.get())
314310
listView.scrollTo(listView.getItems().size() - 1);
@@ -318,7 +314,6 @@ private static final class LogWindowSkin extends SkinBase<LogWindowImpl> {
318314
+ "\"; -fx-font-size: " + config().getFontSize() + "px;");
319315
listView.setCellFactory(x -> new ListCell<>() {
320316
{
321-
x.setSelectionModel(new NoneMultipleSelectionModel<>());
322317
getStyleClass().add("log-window-list-cell");
323318
Region clippedContainer = (Region) listView.lookup(".clipped-container");
324319
if (clippedContainer != null) {
@@ -328,32 +323,6 @@ private static final class LogWindowSkin extends SkinBase<LogWindowImpl> {
328323
setPadding(new Insets(2));
329324
setWrapText(true);
330325
setGraphic(null);
331-
332-
setOnMouseClicked(event -> {
333-
if (event.getButton() != MouseButton.PRIMARY)
334-
return;
335-
336-
if (!event.isControlDown()) {
337-
for (ListCell<Log> logListCell : selected) {
338-
if (logListCell != this) {
339-
logListCell.pseudoClassStateChanged(SELECTED, false);
340-
if (logListCell.getItem() != null) {
341-
logListCell.getItem().setSelected(false);
342-
}
343-
}
344-
}
345-
346-
selected.clear();
347-
}
348-
349-
selected.add(this);
350-
pseudoClassStateChanged(SELECTED, true);
351-
if (getItem() != null) {
352-
getItem().setSelected(true);
353-
}
354-
355-
event.consume();
356-
});
357326
}
358327

359328
@Override
@@ -367,7 +336,6 @@ protected void updateItem(Log item, boolean empty) {
367336
pseudoClassStateChanged(INFO, !empty && item.getLevel() == Log4jLevel.INFO);
368337
pseudoClassStateChanged(DEBUG, !empty && item.getLevel() == Log4jLevel.DEBUG);
369338
pseudoClassStateChanged(TRACE, !empty && item.getLevel() == Log4jLevel.TRACE);
370-
pseudoClassStateChanged(SELECTED, !empty && item.isSelected());
371339

372340
if (empty) {
373341
setText(null);
@@ -379,10 +347,13 @@ protected void updateItem(Log item, boolean empty) {
379347

380348
listView.setOnKeyPressed(event -> {
381349
if (event.isControlDown() && event.getCode() == KeyCode.C) {
350+
if (listView.getSelectionModel().isEmpty())
351+
return;
352+
382353
StringBuilder stringBuilder = new StringBuilder();
383354

384-
for (Log item : listView.getItems()) {
385-
if (item != null && item.isSelected()) {
355+
for (Log item : listView.getSelectionModel().getSelectedItems()) {
356+
if (item != null) {
386357
if (item.getLog() != null)
387358
stringBuilder.append(item.getLog());
388359
stringBuilder.append('\n');

0 commit comments

Comments
 (0)