TagSpaces is an offline, open source, document manager with tagging support
fix: closing the deleted files after deletion in mobile devices
Ilian Sapundshievf6a592655fe6
diff --git a/src/renderer/hooks/OpenedEntryContextProvider.tsx b/src/renderer/hooks/OpenedEntryContextProvider.tsxindex 0dbb7dc1d..a837e19d9 100644--- a/src/renderer/hooks/OpenedEntryContextProvider.tsx+++ b/src/renderer/hooks/OpenedEntryContextProvider.tsx@@ -53,6 +53,7 @@ import {locationType,} from '@tagspaces/tagspaces-common/misc';import {+ cleanFrontDirSeparator,cleanRootPath,cleanTrailingDirSeparator,extractContainingDirectoryPath,@@ -238,11 +239,26 @@ export const OpenedEntryContextProvider = ({openFsEntry(action.entry);}} else if (action.action === 'delete') {- if (- currentEntry.current &&- currentEntry.current.path.startsWith(action.entry.path)- ) {- actuallyCloseFiles();+ // Close the viewer/editor when the opened entry itself is deleted, or+ // when a deleted folder contains it. Normalize both paths first:+ // a raw `startsWith` breaks when the opened entry's path and the+ // deleted entry's path differ by a leading/trailing separator (S3+ // locations, entries opened via links/search) and also matches+ // siblings by accident (e.g. '/a/bc.txt'.startsWith('/a/b')). See the+ // path-handling notes in CLAUDE.md.+ if (currentEntry.current && action.entry?.path !== undefined) {+ const normPath = (p: string) =>+ cleanTrailingDirSeparator(+ cleanFrontDirSeparator(p).replaceAll('\\', '/'),+ );+ const openedNorm = normPath(currentEntry.current.path);+ const deletedNorm = normPath(action.entry.path);+ if (+ openedNorm === deletedNorm ||+ openedNorm.startsWith(deletedNorm + '/')+ ) {+ actuallyCloseFiles();+ }}} else if (action.action === 'update' || action.action === 'move') {if (diff --git a/tests/e2e/fileopener.pw.e2e.js b/tests/e2e/fileopener.pw.e2e.jsindex 8c9361c7c..dda53f7f1 100644--- a/tests/e2e/fileopener.pw.e2e.js+++ b/tests/e2e/fileopener.pw.e2e.js@@ -346,11 +346,32 @@ test.describe('TST08 - File folder properties', () => {await clickOn('[data-tid=deleteEntryTID]');await clickOn('[data-tid=confirmDeleteTID]');await expectElementExist(getGridFileSelector(fileName), false, 5000);+ // Deleting the opened entry must also close its viewer/editor.+ await expectElementExist(+ '[data-tid=OpenedTID' + dataTidFormat(fileName) + ']',+ false,+ 5000,+ );await expectMetaFilesExist(arrayMeta, false);await setSettings('[data-tid=settingsSetPersistTagsInFileName]', true);});+ test('TST0813b - Delete file opened in viewer closes it [web,s3,electron]', async () => {+ const fileName = 'sample.txt';+ // Open in the actual file viewer (not the properties panel).+ await openFile(fileName);+ await clickOn('[data-tid=propsActionsMenuTID]');+ await clickOn('[data-tid=deleteEntryTID]');+ await clickOn('[data-tid=confirmDeleteTID]');+ await expectElementExist(getGridFileSelector(fileName), false, 5000);+ await expectElementExist(+ '[data-tid=OpenedTID' + dataTidFormat(fileName) + ']',+ false,+ 5000,+ );+ });+test('TST0813a - Delete file and check revisions deleted [web,s3,electron,_pro]', async () => {const fileName = 'sample.txt';await openFile(fileName);