Skip to content

Commit

Permalink
Fix workbench.action.files.newUntitledFile (#14754)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored Jan 29, 2025
1 parent 2ab5059 commit 2ee133f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
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

0 comments on commit 2ee133f

Please sign in to comment.