Skip to content
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

fix #219932 (#219933) resolve the behavior of Open File (ctrl +o) #219942

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/vs/workbench/browser/actions/workspaceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder, hasWorkspaceFileExtension } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/common/workspaceEditing';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ITextEditorService } from 'vs/workbench/services/textfile/common/textEditorService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL, PICK_WORKSPACE_FOLDER_COMMAND_ID, SET_ROOT_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/workspaceCommands';
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
Expand All @@ -24,6 +25,9 @@ import { IsMacNativeContext } from 'vs/platform/contextkey/common/contextkeys';
import { ILocalizedString } from 'vs/platform/action/common/action';
import { Categories } from 'vs/platform/action/common/actionCommonCategories';




const workspacesCategory: ILocalizedString = localize2('workspaces', 'Workspaces');

export class OpenFileAction extends Action2 {
Expand All @@ -46,11 +50,19 @@ export class OpenFileAction extends Action2 {

override async run(accessor: ServicesAccessor, data?: ITelemetryData): Promise<void> {
const fileDialogService = accessor.get(IFileDialogService);

return fileDialogService.pickFileAndOpen({ forceNewWindow: false, telemetryExtraData: data });
const activeTextEditor = accessor.get(ITextEditorService).activeTextEditor;

if (activeTextEditor) {
const filePath = activeTextEditor.document.uri.fsPath;
const folderPath = path.dirname(filePath);
return fileDialogService.pickFileAndOpen({ folderUri: folderPath, telemetryExtraData: data });
} else {
// Handle the case where no editor is active (optional)
}
}
}


export class OpenFolderAction extends Action2 {

static readonly ID = 'workbench.action.files.openFolder';
Expand Down