fix: navigatie
This commit is contained in:
+25
-1
@@ -9,6 +9,7 @@ let state = {
|
||||
currentRowIndex: -1,
|
||||
selectionAnchorIndex: null,
|
||||
pendingSelectionPath: null,
|
||||
returnFocusName: null,
|
||||
},
|
||||
right: {
|
||||
currentPath: "/Volumes",
|
||||
@@ -19,6 +20,7 @@ let state = {
|
||||
currentRowIndex: -1,
|
||||
selectionAnchorIndex: null,
|
||||
pendingSelectionPath: null,
|
||||
returnFocusName: null,
|
||||
},
|
||||
},
|
||||
activePane: "left",
|
||||
@@ -2210,10 +2212,15 @@ function navigateToParent(pane) {
|
||||
if (!parentPath) {
|
||||
return;
|
||||
}
|
||||
model.pendingSelectionPath = childPath;
|
||||
prepareParentReturnRestore(pane, childPath);
|
||||
navigateTo(pane, parentPath);
|
||||
}
|
||||
|
||||
function prepareParentReturnRestore(pane, childPath) {
|
||||
const model = paneState(pane);
|
||||
model.returnFocusName = baseName(childPath);
|
||||
}
|
||||
|
||||
function baseName(path) {
|
||||
const index = path.lastIndexOf("/");
|
||||
return index >= 0 ? path.slice(index + 1) : path;
|
||||
@@ -2618,6 +2625,7 @@ async function loadBrowsePane(pane) {
|
||||
}
|
||||
|
||||
renderPaneItems(pane);
|
||||
restoreParentReturnFocus(pane, visibleItems);
|
||||
scrollCurrentRowIntoView(pane);
|
||||
setStatus(`Loaded ${pane}: ${data.path}`);
|
||||
} catch (err) {
|
||||
@@ -2625,6 +2633,22 @@ async function loadBrowsePane(pane) {
|
||||
}
|
||||
}
|
||||
|
||||
function restoreParentReturnFocus(pane, visibleItems) {
|
||||
const model = paneState(pane);
|
||||
const returningFromChildName = model.returnFocusName;
|
||||
model.returnFocusName = null;
|
||||
if (!returningFromChildName) {
|
||||
return;
|
||||
}
|
||||
const returnIndex = visibleItems.findIndex((item) => !item.isParent && item.name === returningFromChildName);
|
||||
if (returnIndex < 0) {
|
||||
return;
|
||||
}
|
||||
const returnItem = visibleItems[returnIndex];
|
||||
model.currentRowIndex = returnIndex;
|
||||
renderPaneItems(pane);
|
||||
}
|
||||
|
||||
function navigateTo(pane, path) {
|
||||
closeContextMenu();
|
||||
const model = paneState(pane);
|
||||
|
||||
Reference in New Issue
Block a user