-
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 all commits
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 |
|---|---|---|
|
|
@@ -60,6 +60,8 @@ import { | |
| isContainer as getIsContainer, | ||
| } from "./utils"; | ||
|
|
||
| const SAS_FILE_SEPARATOR = "~fs~"; | ||
|
|
||
| class ContentDataProvider | ||
| implements | ||
| TreeDataProvider<ContentItem>, | ||
|
|
@@ -667,20 +669,120 @@ class ContentDataProvider | |
| if (!targetUri) { | ||
| return false; | ||
| } | ||
|
|
||
| const closing = closeFileIfOpen(item); | ||
| if (!(await closing)) { | ||
| const closedFiles = await closing; | ||
| if (!closedFiles) { | ||
tarikutk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) { | ||
| await commands.executeCommand("vscode.open", newFileUri); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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 (error) { | ||
| console.error("Failed to decode URI component:", error); | ||
| return uriWithoutPrefix; | ||
| } | ||
| } catch (error) { | ||
| console.error("Failed to extract path from URI:", error); | ||
| 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 + SAS_FILE_SEPARATOR) | ||
| ) { | ||
| 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( | ||
| `${newItemUri.scheme}:/${filename}?${encodeURIComponent(newQuery)}`, | ||
| ); | ||
| } catch (error) { | ||
| console.error("Failed to construct new file URI:", error); | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| private async handleContentItemDrop( | ||
| target: ContentItem, | ||
| item: ContentItem, | ||
|
|
||
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.
Fwiw, this is sas server specific. Anything that is specific to connection type should happen in the adapter if possible.