Skip to content
Open
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
43 changes: 38 additions & 5 deletions packages/application-extension/src/settingconnector.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
/**
Expand All @@ -45,7 +51,7 @@ export class SettingConnector extends BaseSettingConnector {
id: string
): Promise<ISettingRegistry.IPlugin | undefined> {
const plugin = await super.fetch(id);
return plugin && Private.overrideDefaults(plugin);
return plugin && Private.applyOverrides(plugin);
}

override async list(query: 'ids'): Promise<{ ids: string[] }>;
Expand All @@ -59,19 +65,25 @@ 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) };
}
}

/**
* 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];
Expand All @@ -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;
}
}
13 changes: 13 additions & 0 deletions ui-tests/test/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
13 changes: 13 additions & 0 deletions ui-tests/test/menus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading