Skip to content

Commit

Permalink
Use spaces as separators in file names
Browse files Browse the repository at this point in the history
Use spaces instead of underscores as separators inside file names for
newly created files/folders.

Signed-off-by: Alexandra Buzila <[email protected]>
  • Loading branch information
AlexandraBuzila committed Feb 17, 2022
1 parent 45a2eaf commit 84601d3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/filesystem/src/browser/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ export class FileService {
// if target exists get valid target
if (exists && !overwrite) {
const parent = await this.resolve(target.parent);
const name = isSameResourceWithDifferentPathCase ? target.path.name : target.path.name + '_copy';
const name = isSameResourceWithDifferentPathCase ? target.path.name : target.path.name + FileSystemUtils.FILE_NAME_SEPARATOR + 'copy';
target = FileSystemUtils.generateUniqueResourceURI(target.parent, parent, name, target.path.ext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class FileTreeModel extends CompressedTreeModel implements LocationServic
try {
if (source.path.toString() === target.uri.path.toString() || source.path.toString() === targetUri.path.toString()) {
const parent = await this.fileService.resolve(source.parent);
const name = source.path.name + '_copy';
const name = source.path.name + FileSystemUtils.FILE_NAME_SEPARATOR + 'copy';
targetUri = FileSystemUtils.generateUniqueResourceURI(source.parent, parent, name, source.path.ext);
}
await this.fileService.copy(source, targetUri);
Expand Down
3 changes: 2 additions & 1 deletion packages/filesystem/src/common/filesystem-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { FileStat } from '../common/files';
import URI from '@theia/core/lib/common/uri';

export namespace FileSystemUtils {
export const FILE_NAME_SEPARATOR = ' ';

/**
* Generate unique URI for a given parent which does not collide
Expand All @@ -34,7 +35,7 @@ export namespace FileSystemUtils {
let base = name + ext;
while (children.some(child => child.path.base === base)) {
index = index + 1;
base = name + '_' + index + ext;
base = name + FILE_NAME_SEPARATOR + index + ext;
}
return parentUri.resolve(base);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class WorkspaceDuplicateHandler implements UriCommandHandler<URI[]> {
try {
const parent = await this.fileService.resolve(uri.parent);
const parentUri = parent.resource;
const name = uri.path.name + '_copy';
const name = uri.path.name + FileSystemUtils.FILE_NAME_SEPARATOR + 'copy';
const ext = uri.path.ext;
const target = FileSystemUtils.generateUniqueResourceURI(parentUri, parent, name, ext);
await this.fileService.copy(uri, target);
Expand Down

0 comments on commit 84601d3

Please sign in to comment.