Skip to content

Commit a65f946

Browse files
pull out find code into helper function
1 parent 2fdb3e8 commit a65f946

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

src/features/ExtensionCommands.ts

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -385,22 +385,7 @@ export class ExtensionCommandsFeature implements IFeature {
385385
private closeFile(filePath: string): Thenable<EditorOperationResponse> {
386386

387387
var promise: Thenable<EditorOperationResponse>;
388-
389-
var normalizedFilePath = this.normalizeFilePath(filePath);
390-
391-
// since Windows is case-insensitive, we need to normalize it differently
392-
var canFind = vscode.workspace.textDocuments.find(doc => {
393-
var docPath, platform = os.platform();
394-
if (platform == "win32" || platform == "darwin") {
395-
// for windows paths, they are normalized to be lowercase
396-
docPath = doc.fileName.toLowerCase();
397-
} else {
398-
docPath = doc.fileName;
399-
}
400-
return docPath == normalizedFilePath;
401-
});
402-
403-
if (canFind)
388+
if (this.findTextDocument(this.normalizeFilePath(filePath)))
404389
{
405390
promise =
406391
vscode.workspace.openTextDocument(filePath)
@@ -419,22 +404,7 @@ export class ExtensionCommandsFeature implements IFeature {
419404
private saveFile(filePath: string): Thenable<EditorOperationResponse> {
420405

421406
var promise: Thenable<EditorOperationResponse>;
422-
423-
var normalizedFilePath = this.normalizeFilePath(filePath);
424-
425-
// since Windows is case-insensitive, we need to normalize it differently
426-
var canFind = vscode.workspace.textDocuments.find(doc => {
427-
var docPath, platform = os.platform();
428-
if (platform == "win32" || platform == "darwin") {
429-
// for windows paths, they are normalized to be lowercase
430-
docPath = doc.fileName.toLowerCase();
431-
} else {
432-
docPath = doc.fileName;
433-
}
434-
return docPath == normalizedFilePath;
435-
});
436-
437-
if (canFind)
407+
if (this.findTextDocument(this.normalizeFilePath(filePath)))
438408
{
439409
promise =
440410
vscode.workspace.openTextDocument(filePath)
@@ -484,6 +454,22 @@ export class ExtensionCommandsFeature implements IFeature {
484454
}
485455
}
486456

457+
private findTextDocument(filePath: string): boolean {
458+
// since Windows and macOS are case-insensitive, we need to normalize them differently
459+
var canFind = vscode.workspace.textDocuments.find(doc => {
460+
var docPath, platform = os.platform();
461+
if (platform == "win32" || platform == "darwin") {
462+
// for Windows and macOS paths, they are normalized to be lowercase
463+
docPath = doc.fileName.toLowerCase();
464+
} else {
465+
docPath = doc.fileName;
466+
}
467+
return docPath == filePath;
468+
});
469+
470+
return canFind != null;
471+
}
472+
487473
private setSelection(details: SetSelectionRequestArguments): EditorOperationResponse {
488474
vscode.window.activeTextEditor.selections = [
489475
new vscode.Selection(

0 commit comments

Comments
 (0)