Skip to content

Commit

Permalink
abstract path checking and manipulation into getLocalPath
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-i committed Aug 28, 2024
1 parent cb0693d commit a9765cf
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ function getSelectedFileBaseName(widget: FileBrowser | null): string | null {
return parts.join('.');
}

// Get the file name, with all parent directories, of the currently selected file.
/**
* Get the file name of the currently selected file with all parent directories, check
* for and remove "RTC" drive prefix potentially added by jupyter-collaboration.
*/
function getSelectedFilePath(
widget: FileBrowser | null,
contents: Contents.IManager
Expand All @@ -151,12 +154,18 @@ function getSelectedFilePath(
if (selectedItem === null) {
return null;
}
return getLocalPath(selectedItem.path, contents);
}

if (contents.driveName(selectedItem.path) === 'RTC') {
return contents.localPath(selectedItem.path);
/**
* Checks if path contains "RTC" drive prefix potentially added by jupyter-collaboration
* and returns a local path removing "RTC" prefix if needed
*/
function getLocalPath(path: string, contents: Contents.IManager): string {
if (contents.driveName(path) === 'RTC') {
return contents.localPath(path);
}

return selectedItem.path;
return path;
}

// Get the containing directory of the file at a particular path.
Expand Down

0 comments on commit a9765cf

Please sign in to comment.