-
Notifications
You must be signed in to change notification settings - Fork 62
fix: reopens files that were opened when dragging and dropping files or folders #1704
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -667,20 +667,117 @@ class ContentDataProvider | |
| if (!targetUri) { | ||
| return false; | ||
| } | ||
|
|
||
| const closing = closeFileIfOpen(item); | ||
| if (!(await closing)) { | ||
| const closedFiles = await closing; | ||
| if (!closedFiles) { | ||
| return false; | ||
| } | ||
|
|
||
| const newUri = await this.model.moveTo(item, targetUri); | ||
| if (closing !== true) { | ||
| commands.executeCommand("vscode.open", newUri); | ||
| if (Array.isArray(closedFiles) && closedFiles.length > 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With drag and drop, at the moment, we call Is there an issue where the |
||
| // Reopen only the files that were closed | ||
| for (const closedFileUri of closedFiles) { | ||
| // Calculate the new URI for each closed file | ||
| const newFileUri = this.calculateNewFileUri( | ||
| closedFileUri, | ||
| item, | ||
| newUri, | ||
| ); | ||
| if (newFileUri) { | ||
| commands.executeCommand("vscode.open", newFileUri); | ||
| } | ||
tarikutk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| return !!newUri; | ||
| } | ||
|
|
||
| private calculateNewFileUri( | ||
| closedFileUri: Uri, | ||
| movedItem: ContentItem, | ||
| newItemUri: boolean | Uri, | ||
| ): Uri | null { | ||
| if (typeof newItemUri === "boolean" || !newItemUri) { | ||
tarikutk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return null; | ||
| } | ||
|
|
||
| const isFolder = getIsContainer(movedItem); | ||
|
|
||
| // If the moved item is a file and matches the closed file, return the new URI | ||
| if ( | ||
| !isFolder && | ||
| closedFileUri.toString() === movedItem.vscUri?.toString() | ||
| ) { | ||
| return newItemUri; | ||
| } | ||
|
|
||
| // If the moved item is a folder, calculate the new path for files within it | ||
| if (isFolder && movedItem.vscUri) { | ||
| const extractPathFromUri = (uri: string): string => { | ||
| try { | ||
| const queryStart = uri.indexOf("?"); | ||
| if (queryStart === -1) { | ||
| return ""; | ||
| } | ||
|
|
||
| const queryString = uri.substring(queryStart + 1); | ||
|
|
||
| const decodedQuery = decodeURIComponent(queryString); | ||
| const idMatch = decodedQuery.match(/id=(.+)/); | ||
| if (!idMatch || !idMatch[1]) { | ||
| return ""; | ||
| } | ||
| const uriWithoutPrefix = idMatch[1].replace( | ||
| /\/compute\/sessions\/[a-zA-Z0-9-]*\/files\//, | ||
| "", | ||
| ); | ||
|
Comment on lines
+732
to
+735
|
||
| try { | ||
| return decodeURIComponent(uriWithoutPrefix); | ||
| } catch { | ||
tarikutk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return uriWithoutPrefix; | ||
| } | ||
| } catch { | ||
tarikutk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ""; | ||
| } | ||
| }; | ||
|
|
||
| const oldBasePath = extractPathFromUri(movedItem.vscUri.toString()); | ||
| const closedFilePath = extractPathFromUri(closedFileUri.toString()); | ||
|
|
||
| // Check if the closed file was inside the moved folder | ||
| if ( | ||
| oldBasePath && | ||
| closedFilePath && | ||
| closedFilePath.startsWith(oldBasePath + "~fs~") | ||
tarikutk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
| try { | ||
| const relativePath = closedFilePath.substring(oldBasePath.length); | ||
| const filename = relativePath.replace(/^~fs~/, ""); | ||
tarikutk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const newUriStr = newItemUri.toString(); | ||
| // Extract and modify the query to append the filename path | ||
| const queryMatch = newUriStr.match(/\?(.+)$/); | ||
| if (!queryMatch) { | ||
| return null; | ||
| } | ||
|
|
||
| const decodedQuery = decodeURIComponent(queryMatch[1]); | ||
| const newQuery = decodedQuery.replace( | ||
| /(\/files\/[^&]*)/, | ||
| `$1~fs~${filename}`, | ||
| ); | ||
tarikutk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return Uri.parse( | ||
| `sasServer:/${filename}?${encodeURIComponent(newQuery)}`, | ||
tarikutk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| } catch { | ||
tarikutk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return null; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| private async handleContentItemDrop( | ||
| target: ContentItem, | ||
| item: ContentItem, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.