Repository navigation
fix: keep sub-paths of open tabs when a folder is renamed or moved #3140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
divya0795
wants to merge
2
commits into
Acode-Foundation:main
Choose a base branch
from
divya0795:fix/folder-rename-tab-paths
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { afterEach, expect, test, vi } from "vitest"; | ||
|
|
||
| vi.mock("fileSystem", () => ({ default: vi.fn() })); | ||
| vi.mock("dialogs/alert", () => ({ default: vi.fn() })); | ||
| vi.mock("lib/adRewards", () => ({ default: {} })); | ||
| vi.mock("lib/config", () => ({ default: {} })); | ||
| vi.mock("lib/fileIcons", () => ({ default: {} })); | ||
| vi.mock("lib/startAd", () => ({ | ||
| interstitialAd: {}, | ||
| requestBannerForPage: vi.fn(), | ||
| })); | ||
|
|
||
| import helpers from "utils/helpers"; | ||
|
|
||
| afterEach(() => vi.unstubAllGlobals()); | ||
|
|
||
| function openTabs(...uris) { | ||
| const files = uris.map((uri) => ({ | ||
| uri, | ||
| filename: uri.slice(uri.lastIndexOf("/") + 1), | ||
| })); | ||
| vi.stubGlobal("editorManager", { | ||
| files, | ||
| onupdate: vi.fn(), | ||
| emit: vi.fn(), | ||
| }); | ||
| return files; | ||
| } | ||
|
|
||
| const uris = (files) => files.map((file) => file.uri); | ||
|
|
||
| test("renaming a folder keeps the sub-path of nested open files", () => { | ||
| const files = openTabs( | ||
| "file:///sdcard/proj/src/index.js", | ||
| "file:///sdcard/proj/src/components/Button.js", | ||
| "file:///sdcard/proj/src/a/b/c.js", | ||
| ); | ||
| helpers.updateUriOfAllActiveFiles( | ||
| "file:///sdcard/proj/src/", | ||
| "file:///sdcard/proj/lib/", | ||
| ); | ||
| expect(uris(files)).toEqual([ | ||
| "file:///sdcard/proj/lib/index.js", | ||
| "file:///sdcard/proj/lib/components/Button.js", | ||
| "file:///sdcard/proj/lib/a/b/c.js", | ||
| ]); | ||
| }); | ||
|
|
||
| test("renaming a folder leaves sibling folders that share its name prefix alone", () => { | ||
| const files = openTabs( | ||
| "file:///sdcard/proj/src/index.js", | ||
| "file:///sdcard/proj/src-old/legacy.js", | ||
| "file:///sdcard/proj/src2/main.js", | ||
| ); | ||
| helpers.updateUriOfAllActiveFiles( | ||
| "file:///sdcard/proj/src", | ||
| "file:///sdcard/proj/lib", | ||
| ); | ||
| expect(uris(files)).toEqual([ | ||
| "file:///sdcard/proj/lib/index.js", | ||
| "file:///sdcard/proj/src-old/legacy.js", | ||
| "file:///sdcard/proj/src2/main.js", | ||
| ]); | ||
| }); | ||
|
|
||
| test("deleting a folder only detaches files inside it", () => { | ||
| const files = openTabs( | ||
| "file:///sdcard/proj/src/components/Button.js", | ||
| "file:///sdcard/proj/src-old/legacy.js", | ||
| ); | ||
| helpers.updateUriOfAllActiveFiles("file:///sdcard/proj/src", null); | ||
| expect(uris(files)).toEqual([null, "file:///sdcard/proj/src-old/legacy.js"]); | ||
| }); | ||
|
|
||
| test("renaming an open file points its tab at the new name", () => { | ||
| const files = openTabs( | ||
| "file:///sdcard/proj/old.js", | ||
| "file:///sdcard/proj/old.json", | ||
| ); | ||
| helpers.updateUriOfAllActiveFiles( | ||
| "file:///sdcard/proj/old.js", | ||
| "file:///sdcard/proj/new.js", | ||
| ); | ||
| expect(uris(files)).toEqual([ | ||
| "file:///sdcard/proj/new.js", | ||
| "file:///sdcard/proj/old.json", | ||
| ]); | ||
| }); | ||
|
|
||
| test("removing a SAF storage detaches the tabs opened from it", () => { | ||
| const tree = | ||
| "content://com.android.externalstorage.documents/tree/primary%3ATesthtml"; | ||
| const files = openTabs( | ||
| `${tree}::primary:Testhtml/Styles/index.html`, | ||
| `${tree}2::primary:Testhtml2/index.html`, | ||
| ); | ||
| helpers.updateUriOfAllActiveFiles(tree, null); | ||
| expect(uris(files)).toEqual([null, `${tree}2::primary:Testhtml2/index.html`]); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
::match applies to ordinary folders, not just SAF tree roots. Deletingsftp://profile/project/srcalso detaches a tab atsftp://profile/project/src::backup/index.js, even though that separate folder still exists. SFTP listings preserve these valid server filenames. The tab becomes marked deleted and loses its save location.Limit this extra match to bare SAF tree URIs, and add a test that leaves a non-SAF sibling containing
::attached.