fixed column visibility while reloading on background

This commit is contained in:
Radek Davidek 2026-02-20 14:25:33 +01:00
parent a7a86059a8
commit a92fe10581
2 changed files with 64 additions and 20 deletions

View File

@ -15,7 +15,7 @@ import java.io.InputStreamReader;
*/
public class MainApp {
public static final String APP_VERSION = "1.1.6";
public static final String APP_VERSION = "1.1.7";
public enum OS {
WINDOWS, LINUX, MACOS, UNKNOWN

View File

@ -1185,28 +1185,26 @@ public class FilePanelTab extends JPanel {
updateStatus();
});
} else {
if (autoSelectFirst && fileTable.getRowCount() > 0) {
int startIndex = 0;
fileTable.setRowSelectionInterval(startIndex, startIndex);
// Ensure the first row (usually "..") is visible at the very top
SwingUtilities.invokeLater(() -> {
SwingUtilities.invokeLater(() -> {
if (autoSelectFirst && fileTable.getRowCount() > 0) {
int startIndex = 0;
fileTable.setRowSelectionInterval(startIndex, startIndex);
// Ensure the first row (usually "..") is visible at the very top
fileTable.scrollRectToVisible(fileTable.getCellRect(0, 0, true));
});
}
}
if (postLoadAction != null) {
postLoadAction.run();
}
if (postLoadAction != null) {
postLoadAction.run();
}
if (requestFocus) {
SwingUtilities.invokeLater(() -> {
if (requestFocus) {
try {
fileTable.requestFocusInWindow();
} catch (Exception ignore) {
}
});
}
updateStatus();
}
updateStatus();
});
}
// Notify directory change
@ -1258,7 +1256,21 @@ public class FilePanelTab extends JPanel {
FileItem focused = getFocusedItem();
final String focusedName = (focused != null) ? focused.getName() : null;
final List<String> markedNames = new ArrayList<>();
// Record currently displayed "page" by getting the top-left visible item name to preserve scroll position
final Rectangle visibleRect = fileTable.getVisibleRect();
int firstRowIdx = fileTable.rowAtPoint(visibleRect.getLocation());
int firstColIdx = fileTable.columnAtPoint(visibleRect.getLocation());
final String topVisibleItemName;
if (firstRowIdx >= 0 && firstRowIdx < tableModel.items.size()) {
FileItem item = (viewMode == ViewMode.BRIEF)
? tableModel.getItemFromBriefLayout(firstRowIdx, firstColIdx)
: tableModel.getItem(firstRowIdx);
topVisibleItemName = (item != null) ? item.getName() : null;
} else {
topVisibleItemName = null;
}
final java.util.Set<String> markedNames = new java.util.HashSet<>();
for (FileItem item : tableModel.items) {
if (item.isMarked()) {
markedNames.add(item.getName());
@ -1277,7 +1289,7 @@ public class FilePanelTab extends JPanel {
}
}
// Restore focus
// Restore selection (focus) but don't force scroll to it yet
if (focusedName != null) {
for (int i = 0; i < tableModel.items.size(); i++) {
if (tableModel.items.get(i).getName().equals(focusedName)) {
@ -1288,15 +1300,47 @@ public class FilePanelTab extends JPanel {
briefCurrentColumn = selCol;
fileTable.getSelectionModel().setSelectionInterval(selRow, selRow);
fileTable.getColumnModel().getSelectionModel().setSelectionInterval(selCol, selCol);
fileTable.scrollRectToVisible(fileTable.getCellRect(selRow, selCol, true));
} else {
fileTable.getSelectionModel().setSelectionInterval(row, row);
fileTable.scrollRectToVisible(fileTable.getCellRect(row, 0, true));
}
break;
}
}
}
// Restore "currently displayed page" (viewport) by scrolling to previous top-left item
if (topVisibleItemName != null) {
for (int i = 0; i < tableModel.items.size(); i++) {
if (tableModel.items.get(i).getName().equals(topVisibleItemName)) {
final int row = i;
SwingUtilities.invokeLater(() -> {
if (viewMode == ViewMode.BRIEF) {
int r = row % tableModel.briefRowsPerColumn;
int c = row / tableModel.briefRowsPerColumn;
fileTable.scrollRectToVisible(fileTable.getCellRect(r, c, true));
} else {
fileTable.scrollRectToVisible(fileTable.getCellRect(row, 0, true));
}
});
break;
}
}
} else if (focusedName != null) {
// Fallback: if no top item found but selection exists, make sure selection is visible
for (int i = 0; i < tableModel.items.size(); i++) {
if (tableModel.items.get(i).getName().equals(focusedName)) {
final int row = i;
SwingUtilities.invokeLater(() -> {
if (viewMode == ViewMode.BRIEF) {
fileTable.scrollRectToVisible(fileTable.getCellRect(row % tableModel.briefRowsPerColumn, row / tableModel.briefRowsPerColumn, true));
} else {
fileTable.scrollRectToVisible(fileTable.getCellRect(row, 0, true));
}
});
break;
}
}
}
fileTable.repaint();
});
}