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 workbench.action.files.newUntitledFile #14754

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
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
23 changes: 16 additions & 7 deletions packages/core/src/browser/common-frontend-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { UNTITLED_SCHEME, UntitledResourceResolver } from '../common';
import { LanguageQuickPickService } from './i18n/language-quick-pick-service';
import { SidebarMenu } from './shell/sidebar-menu-widget';
import { UndoRedoHandlerService } from './undo-redo-handler';
import { timeout } from '../common/promise-util';

export namespace CommonMenus {

Expand Down Expand Up @@ -291,13 +292,16 @@ export namespace CommonCommands {
id: 'workbench.action.files.newFile',
category: FILE_CATEGORY
});
// This command immediately opens a new untitled text file
// Some VS Code extensions use this command to create new files
export const NEW_UNTITLED_TEXT_FILE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.files.newUntitledTextFile',
id: 'workbench.action.files.newUntitledFile',
category: FILE_CATEGORY,
label: 'New Untitled Text File'
});
export const NEW_UNTITLED_FILE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.files.newUntitledFile',
// This command opens a quick pick to select a file type to create
export const PICK_NEW_FILE = Command.toDefaultLocalizedCommand({
id: 'workbench.action.files.pickNewFile',
category: CREATE_CATEGORY,
label: 'New File...'
});
Expand Down Expand Up @@ -766,7 +770,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
});

registry.registerMenuAction(CommonMenus.FILE_NEW_TEXT, {
commandId: CommonCommands.NEW_UNTITLED_FILE.id,
commandId: CommonCommands.PICK_NEW_FILE.id,
label: nls.localizeByDefault('New File...'),
order: 'a1'
});
Expand Down Expand Up @@ -1027,10 +1031,15 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
execute: async () => {
const untitledUri = this.untitledResourceResolver.createUntitledURI('', await this.workingDirProvider.getUserWorkingDir());
this.untitledResourceResolver.resolve(untitledUri);
return open(this.openerService, untitledUri);
const editor = await open(this.openerService, untitledUri);
// Wait for all of the listeners of the `onDidOpen` event to be notified
await timeout(50);
// Afterwards, we can return from the command with the newly created editor
// If we don't wait, we return from the command before the plugin API has been notified of the new editor
return editor;
}
});
commandRegistry.registerCommand(CommonCommands.NEW_UNTITLED_FILE, {
commandRegistry.registerCommand(CommonCommands.PICK_NEW_FILE, {
execute: async () => this.showNewFilePicker()
});

Expand Down Expand Up @@ -1187,7 +1196,7 @@ export class CommonFrontendContribution implements FrontendApplicationContributi
keybinding: this.isElectron() ? 'ctrlcmd+n' : 'alt+n',
},
{
command: CommonCommands.NEW_UNTITLED_FILE.id,
command: CommonCommands.PICK_NEW_FILE.id,
keybinding: 'ctrlcmd+alt+n'
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class GettingStartedWidget extends ReactWidget {
tabIndex={0}
onClick={this.doCreateFile}
onKeyDown={this.doCreateFileEnter}>
{CommonCommands.NEW_UNTITLED_FILE.label ?? nls.localizeByDefault('New File...')}
{nls.localizeByDefault('New File...')}
</a>
</div>;

Expand Down Expand Up @@ -481,7 +481,7 @@ export class GettingStartedWidget extends ReactWidget {
/**
* Trigger the create file command.
*/
protected doCreateFile = () => this.commandRegistry.executeCommand(CommonCommands.NEW_UNTITLED_FILE.id);
protected doCreateFile = () => this.commandRegistry.executeCommand(CommonCommands.PICK_NEW_FILE.id);
protected doCreateFileEnter = (e: React.KeyboardEvent) => {
if (this.isEnterKey(e)) {
this.doCreateFile();
Expand Down
Loading