diff --git a/packages/application-extension/src/settingconnector.ts b/packages/application-extension/src/settingconnector.ts index dc7b14fec9..0794a5cb92 100644 --- a/packages/application-extension/src/settingconnector.ts +++ b/packages/application-extension/src/settingconnector.ts @@ -1,6 +1,8 @@ // Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. +import { PageConfig } from '@jupyterlab/coreutils'; + import { ISettingRegistry, SettingConnector as BaseSettingConnector, @@ -29,12 +31,16 @@ const SETTING_OVERRIDES: { }, }; +const FILE_EDITOR_PLUGIN_ID = '@jupyterlab/fileeditor-extension:plugin'; + +const SYNTAX_HIGHLIGHTING_SUBMENU_ID = 'jp-mainmenu-view-codemirror-language'; + /** * A data connector for fetching settings. * * #### Notes - * This connector extends the default JupyterLab setting connector, - * and additionally overrides the default values of some settings. + * This connector extends the default JupyterLab setting connector with + * Jupyter Notebook-specific overrides. */ export class SettingConnector extends BaseSettingConnector { /** @@ -45,7 +51,7 @@ export class SettingConnector extends BaseSettingConnector { id: string ): Promise { const plugin = await super.fetch(id); - return plugin && Private.overrideDefaults(plugin); + return plugin && Private.applyOverrides(plugin); } override async list(query: 'ids'): Promise<{ ids: string[] }>; @@ -59,7 +65,7 @@ export class SettingConnector extends BaseSettingConnector { return super.list(query); } const { ids, values } = await super.list(query); - return { ids, values: values.map(Private.overrideDefaults) }; + return { ids, values: values.map(Private.applyOverrides) }; } } @@ -67,11 +73,17 @@ export class SettingConnector extends BaseSettingConnector { * A namespace for private module data. */ namespace Private { + export function applyOverrides( + plugin: ISettingRegistry.IPlugin + ): ISettingRegistry.IPlugin { + return hideSyntaxHighlightingMenu(overrideDefaults(plugin)); + } + /** * Override the default values of the plugin settings listed * in `SETTING_OVERRIDES`. */ - export function overrideDefaults( + function overrideDefaults( plugin: ISettingRegistry.IPlugin ): ISettingRegistry.IPlugin { const overrides = SETTING_OVERRIDES[plugin.id]; @@ -86,4 +98,25 @@ namespace Private { } return plugin; } + + function hideSyntaxHighlightingMenu( + plugin: ISettingRegistry.IPlugin + ): ISettingRegistry.IPlugin { + const page = PageConfig.getOption('notebookPage'); + if (plugin.id !== FILE_EDITOR_PLUGIN_ID || page === 'edit') { + return plugin; + } + const menus = plugin.schema['jupyter.lab.menus']?.main ?? []; + for (const menu of menus) { + for (const item of menu.items ?? []) { + if ( + item.type === 'submenu' && + item.submenu?.id === SYNTAX_HIGHLIGHTING_SUBMENU_ID + ) { + item.disabled = true; + } + } + } + return plugin; + } } diff --git a/ui-tests/test/editor.spec.ts b/ui-tests/test/editor.spec.ts index f17271f60e..378d43cdd5 100644 --- a/ui-tests/test/editor.spec.ts +++ b/ui-tests/test/editor.spec.ts @@ -92,4 +92,17 @@ test.describe('Editor', () => { const url = page.url(); expect(url).toContain(newName); }); + + test('Should show the Text Editor Syntax Highlighting menu', async ({ + page, + tmpPath, + }) => { + const file = `${tmpPath}/${FILE}`; + await page.goto(`edit/${file}`); + + await page.menu.openLocator('View>Text Editor Syntax Highlighting'); + expect( + await page.menu.isOpen('View>Text Editor Syntax Highlighting') + ).toBeTruthy(); + }); }); diff --git a/ui-tests/test/menus.spec.ts b/ui-tests/test/menus.spec.ts index 7959196a24..5bb42d9749 100644 --- a/ui-tests/test/menus.spec.ts +++ b/ui-tests/test/menus.spec.ts @@ -47,4 +47,17 @@ test.describe('Notebook Menus', () => { expect(await menu?.screenshot()).toMatchSnapshot(imageName.toLowerCase()); }); }); + + test('View menu should not have the Text Editor Syntax Highlighting entry', async ({ + page, + tmpPath, + }) => { + await page.goto(`notebooks/${tmpPath}/${NOTEBOOK}`); + await waitForKernelReady(page); + + await page.menu.open('View'); + expect( + await page.menu.isOpen('View>Text Editor Syntax Highlighting') + ).toBeFalsy(); + }); }); diff --git a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-chromium-linux.png b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-chromium-linux.png index 2fccc38f7c..617399b3be 100644 Binary files a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-chromium-linux.png and b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-chromium-linux.png differ diff --git a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-firefox-linux.png b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-firefox-linux.png index 7e23acff82..edb3bdc5d3 100644 Binary files a/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-firefox-linux.png and b/ui-tests/test/menus.spec.ts-snapshots/opened-menu-view-firefox-linux.png differ