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 changing font size in text editor #16261

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion galata/test/jupyterlab/texteditor.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { expect, test } from '@jupyterlab/galata';
import { expect, IJupyterLabPageFixture, test } from '@jupyterlab/galata';

const DEFAULT_NAME = 'untitled.txt';

Expand Down Expand Up @@ -103,4 +103,42 @@ ut elit.`
const tabHandle = await page.activity.getPanelLocator(DEFAULT_NAME);
expect(await tabHandle?.screenshot()).toMatchSnapshot(imageName);
});

test.describe('Changing a text editor font-size', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks a lot for adding a test for this ❤️

const getFontSize = async (page: IJupyterLabPageFixture) => {
const wrapperElement = page.locator(
'.jp-MainAreaWidget .jp-FileEditor .cm-content.cm-lineWrapping'
);
const computedStyle = await wrapperElement.evaluate(el =>
getComputedStyle(el)
);
return parseInt(computedStyle.fontSize);
};
const createNewTextEditor = async (page: IJupyterLabPageFixture) => {
await page.menu.clickMenuItem('File>New>Text File');

await page.locator(`[role="main"] >> text=${DEFAULT_NAME}`).waitFor();
await page.type('.cm-content', 'text editor');
};
const changeFontSize = async (page: IJupyterLabPageFixture, menuOption) => {
await page.click('text=Settings');
await page.click(`.lm-Menu ul[role="menu"] >> text="${menuOption}"`);
};

test('Should increase a text editor font-size', async ({ page }) => {
await createNewTextEditor(page);
let fontSize = await getFontSize(page);
await changeFontSize(page, 'Increase Text Editor Font Size');

expect(await getFontSize(page)).toEqual(fontSize + 1);
});

test('Should decrease a text editor font-size', async ({ page }) => {
await createNewTextEditor(page);
let fontSize = await getFontSize(page);
await changeFontSize(page, 'Decrease Text Editor Font Size');

expect(await getFontSize(page)).toEqual(fontSize - 1);
});
});
});
5 changes: 4 additions & 1 deletion packages/fileeditor-extension/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,14 @@ export namespace Commands {
style.getPropertyValue('--jp-code-font-size'),
10
);
if (!config.customStyles) {
config.customStyles = {};
}
const currentSize =
(config['customStyles']['fontSize'] ??
extensions.baseConfiguration['customStyles']['fontSize']) ||
cssSize;
config.fontSize = currentSize + delta;
config.customStyles.fontSize = currentSize + delta;
return settingRegistry
.set(id, 'editorConfig', config)
.catch((reason: Error) => {
Expand Down