Skip to content

Commit 4749571

Browse files
authored
fix: Support Open Settings shortcut in the editor title area (#643)
* add "open text editor"
1 parent bfd6936 commit 4749571

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@
199199
"command": "java.formatterSettings",
200200
"category": "Java",
201201
"title": "Open Java Formatter Settings with Preview"
202+
},
203+
{
204+
"command": "java.formatterSettings.showTextEditor",
205+
"category": "Java",
206+
"title": "Open Text Editor",
207+
"icon": "$(go-to-file)"
202208
}
203209
],
204210
"configuration": {
@@ -235,6 +241,12 @@
235241
}
236242
},
237243
"menus": {
244+
"commandPalette": [
245+
{
246+
"command": "java.formatterSettings.showTextEditor",
247+
"when": "false"
248+
}
249+
],
238250
"view/title": [
239251
{
240252
"command": "java.runtime",
@@ -253,6 +265,13 @@
253265
"group": "9_configuration@20",
254266
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+unmanagedFolder\\b)(?=.*?\\b\\+uri\\b)/"
255267
}
268+
],
269+
"editor/title": [
270+
{
271+
"command": "java.formatterSettings.showTextEditor",
272+
"when": "activeCustomEditorId == java.formatterSettingsEditor",
273+
"group": "navigation"
274+
}
256275
]
257276
},
258277
"customEditors": [

src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function initialize(context: vscode.ExtensionContext) {
3333
context.subscriptions.push(instrumentOperationAsVsCodeCommand("java.webview.runCommand", webviewCmdLinkHandler));
3434
context.subscriptions.push(vscode.commands.registerCommand("java.welcome", instrumentCommand(context, "java.welcome", showWelcomeWebview)));
3535
context.subscriptions.push(vscode.commands.registerCommand("java.formatterSettings", instrumentCommand(context, "java.formatterSettings", () => javaFormatterSettingsEditorProvider.showFormatterSettingsEditor())));
36+
context.subscriptions.push(vscode.commands.registerCommand("java.formatterSettings.showTextEditor", instrumentCommand(context, "java.formatterSettings.showTextEditor", javaFormatterSettingsEditorProvider.reopenWithTextEditor)));
3637
context.subscriptions.push(vscode.commands.registerCommand("java.classpathConfiguration", instrumentCommand(context, "java.classpathConfiguration", async () => {
3738
const showCustomizedView: boolean = await getExpService()?.getTreatmentVariableAsync(TreatmentVariables.VSCodeConfig, TreatmentVariables.CustomizedClasspathConfigurationView, true /*checkCache*/) || false;
3839
if (showCustomizedView) {

src/formatter-settings/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ export class JavaFormatterSettingsEditorProvider implements vscode.CustomTextEdi
6161
vscode.commands.executeCommand("vscode.openWith", filePath, "java.formatterSettingsEditor");
6262
}
6363

64+
public reopenWithTextEditor(_context: vscode.ExtensionContext, _operationId: string, uri: any) {
65+
if (uri instanceof vscode.Uri) {
66+
vscode.commands.executeCommand("vscode.openWith", uri, "default");
67+
}
68+
}
69+
6470
public async resolveCustomTextEditor(document: vscode.TextDocument, webviewPanel: vscode.WebviewPanel, _token: vscode.CancellationToken): Promise<void> {
6571

6672
// restrict one webviewpanel only
@@ -78,7 +84,7 @@ export class JavaFormatterSettingsEditorProvider implements vscode.CustomTextEdi
7884
};
7985
this.webviewPanel.onDidDispose(() => {
8086
this.webviewPanel = undefined;
81-
})
87+
});
8288
const resourceUri = this.context.asAbsolutePath("./out/assets/formatter-settings/index.html");
8389
this.webviewPanel.webview.html = await loadTextFromFile(resourceUri);
8490
this.webviewPanel.webview.onDidReceiveMessage(async (e) => {

0 commit comments

Comments
 (0)