Skip to content

Commit 9af1d4f

Browse files
author
David Kutugata
authored
Interactive Window and Native Editor react to font changes in VS Code settings (#7799)
* Make interactive window and native editor take their fontSize and fontFamily from the settings in VS Code. We get them in nativeEditor.tsx and in interactivePanel.tsx to apply them as styles, but we also need to send them as props to eventually assign them in the monaco editor. * Moved style from react code to common.css We now get the VS Code styles from the state of the component, instead of computing a style from an element. * Removed getting the font from nativeEditor and interactivePanel, and put it in the mainStateController * Made the interactiveWindow and the nativeEditor react and change their fonts when the user changes them in VS Code, instead of having to reload. * Changed the font props to be an object instead of two separate props to make it easier to maintain. React Context was not used to avoid making the reuse of components more difficult. * Removed some unnecesary passing around of the font prop * removed unnecesary comments * fixed a failing test
1 parent d78632f commit 9af1d4f

File tree

16 files changed

+96
-14
lines changed

16 files changed

+96
-14
lines changed

news/2 Fixes/7624.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make interactive window and native take their fontSize and fontFamily from the settings in VS Code.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/datascience/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ export interface IDataScienceExtraSettings extends IDataScienceSettings {
394394
extraSettings: {
395395
editorCursor: string;
396396
editorCursorBlink: string;
397+
fontSize: number;
398+
fontFamily: string;
397399
theme: string;
398400
};
399401
intellisenseOptions: {

src/client/datascience/webViewHost.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ export class WebViewHost<IMapping> implements IDisposable {
170170
extraSettings: {
171171
editorCursor: this.getValue(editor, 'cursorStyle', 'line'),
172172
editorCursorBlink: this.getValue(editor, 'cursorBlinking', 'blink'),
173+
fontSize: this.getValue(editor, 'fontSize', 14),
174+
fontFamily: this.getValue(editor, 'fontFamily', 'Consolas, \'Courier New\', monospace'),
173175
theme: theme
174176
},
175177
intellisenseOptions: {
@@ -240,6 +242,8 @@ export class WebViewHost<IMapping> implements IDisposable {
240242
// Post a message to our webpanel and update our new datascience settings
241243
private onPossibleSettingsChange = (event: ConfigurationChangeEvent) => {
242244
if (event.affectsConfiguration('workbench.colorTheme') ||
245+
event.affectsConfiguration('editor.fontSize') ||
246+
event.affectsConfiguration('editor.fontFamily') ||
243247
event.affectsConfiguration('editor.cursorStyle') ||
244248
event.affectsConfiguration('editor.cursorBlinking') ||
245249
event.affectsConfiguration('python.dataScience.enableGather')) {

src/datascience-ui/history-react/interactiveCell.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { CollapseButton } from '../interactive-common/collapseButton';
1515
import { ExecutionCount } from '../interactive-common/executionCount';
1616
import { InformationMessages } from '../interactive-common/informationMessages';
1717
import { InputHistory } from '../interactive-common/inputHistory';
18-
import { ICellViewModel } from '../interactive-common/mainState';
18+
import { ICellViewModel, IFont } from '../interactive-common/mainState';
1919
import { IKeyboardEvent } from '../react-common/event';
2020
import { getLocString } from '../react-common/locReactSide';
2121
import { getSettings } from '../react-common/settingsReactSide';
@@ -39,6 +39,7 @@ interface IInteractiveCellProps {
3939
focusedCell?: string;
4040
hideOutput?: boolean;
4141
showLineNumbers?: boolean;
42+
font: IFont;
4243
onCodeChange(changes: monacoEditor.editor.IModelContentChange[], cellId: string, modelId: string): void;
4344
onCodeCreated(code: string, file: string, cellId: string, modelId: string): void;
4445
openLink(uri: monacoEditor.Uri): void;
@@ -211,6 +212,7 @@ export class InteractiveCell extends React.Component<IInteractiveCellProps> {
211212
unfocused={this.onCodeUnfocused}
212213
keyDown={this.props.keyDown}
213214
showLineNumbers={this.props.showLineNumbers}
215+
font={this.props.font}
214216
/>
215217
);
216218
}

src/datascience-ui/history-react/interactivePanel.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export class InteractivePanel extends React.Component<IInteractivePanelProps, IM
6767
}
6868

6969
public render() {
70+
const dynamicFont: React.CSSProperties = {
71+
fontSize: this.state.font.size,
72+
fontFamily: this.state.font.family
73+
};
74+
7075
// Update the state controller with our new state
7176
this.stateController.renderUpdate(this.state);
7277
const progressBar = this.state.busy && !this.props.testMode ? <Progress /> : undefined;
@@ -77,7 +82,7 @@ export class InteractivePanel extends React.Component<IInteractivePanelProps, IM
7782
}
7883

7984
return (
80-
<div id='main-panel' ref={this.mainPanelRef} role='Main'>
85+
<div id='main-panel' ref={this.mainPanelRef} role='Main' style={dynamicFont}>
8186
<div className='styleSetter'>
8287
<style>
8388
{this.state.rootCss}
@@ -222,6 +227,7 @@ export class InteractivePanel extends React.Component<IInteractivePanelProps, IM
222227
onClick={this.clickEditCell}
223228
keyDown={this.editCellKeyDown}
224229
renderCellToolbar={this.renderEditCellToolbar}
230+
font={this.state.font}
225231
/>
226232
</ErrorBoundary>
227233
</div>
@@ -346,6 +352,7 @@ export class InteractivePanel extends React.Component<IInteractivePanelProps, IM
346352
renderCellToolbar={this.renderCellToolbar}
347353
showLineNumbers={cellVM.showLineNumbers}
348354
hideOutput={cellVM.hideOutput}
355+
font={this.state.font}
349356
/>
350357
</ErrorBoundary>
351358
</div>);

src/datascience-ui/interactive-common/cellInput.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { IKeyboardEvent } from '../react-common/event';
1212
import { getLocString } from '../react-common/locReactSide';
1313
import { Code } from './code';
1414
import { InputHistory } from './inputHistory';
15-
import { ICellViewModel } from './mainState';
15+
import { ICellViewModel, IFont } from './mainState';
1616
import { Markdown } from './markdown';
1717

1818
// tslint:disable-next-line: no-require-importss
@@ -28,6 +28,7 @@ interface ICellInputProps {
2828
editorMeasureClassName?: string;
2929
focusedCell?: string;
3030
showLineNumbers?: boolean;
31+
font: IFont;
3132
onCodeChange(changes: monacoEditor.editor.IModelContentChange[], cellId: string, modelId: string): void;
3233
onCodeCreated(code: string, file: string, cellId: string, modelId: string): void;
3334
openLink(uri: monacoEditor.Uri): void;
@@ -128,6 +129,7 @@ export class CellInput extends React.Component<ICellInputProps> {
128129
keyDown={this.onKeyDown}
129130
showLineNumbers={this.props.showLineNumbers}
130131
useQuickEdit={this.props.cellVM.useQuickEdit}
132+
font={this.props.font}
131133
/>
132134
</div>
133135
);
@@ -158,6 +160,7 @@ export class CellInput extends React.Component<ICellInputProps> {
158160
keyDown={this.onKeyDown}
159161
ref={this.markdownRef}
160162
useQuickEdit={false}
163+
font={this.props.font}
161164
/>
162165
</div>
163166
);

src/datascience-ui/interactive-common/code.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { InputHistory } from '../interactive-common/inputHistory';
88
import { IKeyboardEvent } from '../react-common/event';
99
import { getLocString } from '../react-common/locReactSide';
1010
import { Editor } from './editor';
11+
import { IFont } from './mainState';
1112

1213
export interface ICodeProps {
1314
autoFocus: boolean;
@@ -23,6 +24,7 @@ export interface ICodeProps {
2324
editorMeasureClassName?: string;
2425
showLineNumbers?: boolean;
2526
useQuickEdit?: boolean;
27+
font: IFont;
2628
onCreated(code: string, modelId: string): void;
2729
onChange(changes: monacoEditor.editor.IModelContentChange[], modelId: string): void;
2830
openLink(uri: monacoEditor.Uri): void;
@@ -70,6 +72,7 @@ export class Code extends React.Component<ICodeProps, ICodeState> {
7072
unfocused={this.props.unfocused}
7173
showLineNumbers={this.props.showLineNumbers}
7274
useQuickEdit={this.props.useQuickEdit}
75+
font={this.props.font}
7376
/>
7477
<div className={waterMarkClass} role='textbox' onClick={this.clickWatermark}>{this.getWatermarkString()}</div>
7578
</div>

src/datascience-ui/interactive-common/common.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,9 @@ body, html {
146146

147147
.cell-output-text {
148148
white-space: pre-wrap;
149-
font-size: var(--code-font-size);
150-
font-family: var(--code-font-family);
151149
}
152150
.cell-output-text pre {
153151
white-space: pre-wrap;
154-
font-size: var(--code-font-size);
155-
font-family: var(--code-font-family);
156152
}
157153

158154
.cell-output-html {

src/datascience-ui/interactive-common/editor.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { noop } from '../../client/common/utils/misc';
88
import { IKeyboardEvent } from '../react-common/event';
99
import { MonacoEditor } from '../react-common/monacoEditor';
1010
import { InputHistory } from './inputHistory';
11+
import { IFont } from './mainState';
1112

1213
// tslint:disable-next-line: import-name
1314
export interface IEditorProps {
@@ -24,6 +25,7 @@ export interface IEditorProps {
2425
language: string;
2526
showLineNumbers?: boolean;
2627
useQuickEdit?: boolean;
28+
font: IFont;
2729
onCreated(code: string, modelId: string): void;
2830
onChange(changes: monacoEditor.editor.IModelContentChange[], model: monacoEditor.editor.ITextModel): void;
2931
openLink(uri: monacoEditor.Uri): void;
@@ -114,6 +116,8 @@ export class Editor extends React.Component<IEditorProps, IEditorState> {
114116
lineDecorationsWidth: 0,
115117
contextmenu: false,
116118
matchBrackets: false,
119+
fontSize: this.props.font.size,
120+
fontFamily: this.props.font.family,
117121
...this.props.editorOptions
118122
};
119123

0 commit comments

Comments
 (0)