Skip to content

Commit

Permalink
Backport PR #16261: Fix changing font size in text editor (#16285)
Browse files Browse the repository at this point in the history
Co-authored-by: FoSuCloud <49218295+FoSuCloud@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and FoSuCloud committed May 7, 2024
1 parent c3c7a02 commit 94e8eaf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
40 changes: 39 additions & 1 deletion galata/test/jupyterlab/texteditor.test.ts
@@ -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.getPanel(DEFAULT_NAME);
expect(await tabHandle.screenshot()).toMatchSnapshot(imageName);
});

test.describe('Changing a text editor font-size', () => {
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: 5 additions & 0 deletions packages/codemirror/src/editor.ts
Expand Up @@ -572,6 +572,11 @@ export class CodeMirrorEditor implements CodeEditor.IEditor {
changes: Record<string, any>
): void {
configurator.reconfigureExtensions(this._editor, changes);
// when customStyles change and the editor is not initialized
if (changes['customStyles'] && !changes['fontSize']) {
// update the state to change the gutter height
this.editor.setState(this.editor.state);
}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/fileeditor-extension/src/commands.ts
Expand Up @@ -257,11 +257,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

0 comments on commit 94e8eaf

Please sign in to comment.