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 #153860 #155086

Merged
merged 1 commit into from
Jul 13, 2022
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
9 changes: 6 additions & 3 deletions src/vs/workbench/contrib/files/browser/fileCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
{
isOptional: true,
name: 'New Untitled File args',
description: 'The editor view type and language ID if known',
description: 'The editor view type, language ID, or resource path if known',
schema: {
'type': 'object',
'properties': {
Expand All @@ -638,17 +638,20 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
},
'languageId': {
'type': 'string'
},
'path': {
'type': 'string'
}
}
}
}
]
},
handler: async (accessor, args?: { languageId?: string; viewType?: string }) => {
handler: async (accessor, args?: { languageId?: string; viewType?: string; path?: string }) => {
const editorService = accessor.get(IEditorService);

await editorService.openEditor({
resource: undefined,
resource: args?.path ? URI.from({ scheme: Schemas.untitled, path: `Untitled-${args.path}` }) : undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might break untitled assumptions: either it should be an untitled with associated path on disk or not set a resource at all, why is this done?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see for what it was added for. I am a bit worried that this could break the following regex:

private static readonly UNTITLED_REGEX = /Untitled-\d+/;

So far, we had the assumption that Untitled-(number) is for untitled without associated resource and anything else has an associated resource. Untitled with associated resources typically do not ask where to save to because of the path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm is there a way we could make this work? This is a very nice experience so far

options: {
override: args?.viewType,
pinned: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ registerAction2(class extends Action2 {
}
});

type NewFileItem = { commandID: string; title: string; from: string; group: string };
type NewFileItem = { commandID: string; title: string; from: string; group: string; commandArgs?: any };
class NewFileTemplatesManager extends Disposable {
static Instance: NewFileTemplatesManager | undefined;

Expand Down Expand Up @@ -162,12 +162,26 @@ class NewFileTemplatesManager extends Disposable {

disposables.add(this.menu.onDidChange(() => refreshQp(this.allEntries())));

disposables.add(qp.onDidChangeValue((val: string) => {
if (val === '') {
return;
}
const currentTextEntry: NewFileItem = {
commandID: 'workbench.action.files.newUntitledFile',
commandArgs: { languageId: undefined, viewType: undefined, path: val },
title: localize('miNewFileWithName', "New File ({0})", val),
group: 'file',
from: builtInSource,
};
refreshQp([currentTextEntry, ...entries]);
}));

disposables.add(qp.onDidAccept(async e => {
const selected = qp.selectedItems[0] as (IQuickPickItem & NewFileItem);
resolveResult(!!selected);

qp.hide();
if (selected) { await this.commandService.executeCommand(selected.commandID); }
if (selected) { await this.commandService.executeCommand(selected.commandID, selected.commandArgs); }
}));

disposables.add(qp.onDidHide(() => {
Expand Down