From 4f7b13c54a61ded32fe018be75a4a42b5b511f71 Mon Sep 17 00:00:00 2001 From: DianaXWiki Date: Wed, 19 Nov 2025 13:36:20 +0200 Subject: [PATCH] More fixes for tree and categories interferences --- www/common/common-ui-elements.js | 26 +++++++++++++++++++++----- www/common/drive-ui.js | 11 ++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 515b38a8b..049fbff4d 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -4584,7 +4584,7 @@ define([ config.openFolders = config.openFolders || []; config.currentPath = config.currentPath || null; - // Check if current path is a subpath of given path (is viewing a child folder) + // Check if current path is a subpath of given path var isSubpath = function(child, parent) { if (!child || !parent || child.length <= parent.length) { return false; } for (var i = 0; i < parent.length; i++) { @@ -4603,9 +4603,12 @@ define([ } } } - // Auto-expand parent folders of current path - if (config.currentPath && isSubpath(config.currentPath, path) && path.length < config.currentPath.length) { - return true; + // Auto-expand parent folders of current path, but only when viewing tree + if (config.currentPath && config.rootPath && isSubpath(config.currentPath, path) && path.length < config.currentPath.length) { + if (config.currentPath.length > 0 && config.rootPath.length > 0 && + config.currentPath[0] === config.rootPath[0]) { + return true; + } } return false; @@ -4683,7 +4686,20 @@ define([ } } }); - if (shouldBeOpened(path) || hasOpenedChild(path)) { + // Auto-expand if explicitly marked as opened + var shouldExpand = shouldBeOpened(path); + + // Also expand if has opened children, but only when viewing this tree + if (!shouldExpand && hasOpenedChild(path)) { + // Check if we're currently viewing this tree (same root category) + if (config.currentPath && config.rootPath && + config.currentPath.length > 0 && config.rootPath.length > 0 && + config.currentPath[0] === config.rootPath[0]) { + shouldExpand = true; + } + } + + if (shouldExpand) { $element.removeClass('cp-app-drive-element-collapsed'); $collapse.empty().append($expandedIcon.clone()); } diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 87d75f4fd..6335cf6ad 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -4614,7 +4614,7 @@ define([ newPath.push(key); var isSharedFolder = manager.isSharedFolder(root[key]) && root[key]; var sfId = manager.isInSharedFolder(newPath) || (isSharedFolder && root[key]); - var folderName = key, $icon, subfolder; + var $icon, isCurrentFolder, subfolder, folderName = key; if (isSharedFolder) { var navPath = newPath.slice(); navPath.push(manager.user.userObject.ROOT); @@ -4624,7 +4624,8 @@ define([ // Fix name var sfData = manager.getSharedFolderData(sfId); folderName = sfData.title || sfData.lastTitle || Messages.fm_deletedFolder; - var isCurrentFolder = manager.comparePath(navPath, currentPath); + isCurrentFolder = manager.comparePath(navPath, currentPath); + // Fix icon $icon = isCurrentFolder ? $sharedFolderOpenedIcon : $sharedFolderIcon; data.content[key] = { name: folderName, @@ -4636,8 +4637,7 @@ define([ } else { var isEmpty = manager.isFolderEmpty(root[key]); subfolder = manager.hasSubfolder(root[key]); - // Check if this is the current folder - var isCurrentFolder = manager.comparePath(newPath, currentPath); + isCurrentFolder = manager.comparePath(newPath, currentPath); $icon = isEmpty ? (isCurrentFolder ? $folderOpenedEmptyIcon : $folderEmptyIcon) : (isCurrentFolder ? $folderOpenedIcon : $folderIcon); @@ -4722,7 +4722,8 @@ define([ }, onFolderExpanded: function (clickedPath, isOpen) { LS.setFolderOpened(clickedPath, isOpen); - // Also remove all child folders when collapsing a parent + if (clickedPath.length === 1) { return; } + // When collapsing a folder, close all its children if (!isOpen) { LS.removeFoldersOpened(clickedPath); }