Skip to content

Commit a6292a7

Browse files
committed
Make font size of preview configurable in settings
1 parent 6547c86 commit a6292a7

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

schema/snippets.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
"tags":["machine learning"]
6363
}
6464
]
65+
},
66+
"snippetPreviewFontSize": {
67+
"title": "Font Size of Preview",
68+
"type": "number",
69+
"default": 3,
70+
"description": "Change the font size of preview to see its content"
6571
}
6672
},
6773
"additionalProperties": false,

src/CodeSnippetPreview.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Message, MessageLoop } from '@lumino/messaging';
99
import { PromiseDelegate } from '@lumino/coreutils';
1010
import { ArrayExt } from '@lumino/algorithm';
1111

12-
import { ICodeSnippet } from './CodeSnippetService';
12+
import { ICodeSnippet, CodeSnippetService } from './CodeSnippetService';
1313

1414
/**
1515
* The class name for preview box
@@ -46,6 +46,7 @@ export class Preview<T> extends Widget {
4646
editor: CodeEditor.IEditor;
4747
codeSnippet: ICodeSnippet;
4848
editorServices: IEditorServices;
49+
codeSnippetService: CodeSnippetService;
4950
private _hasRefreshedSinceAttach: boolean;
5051
constructor(
5152
options: Partial<Preview.IOptions<T>> = {},
@@ -57,6 +58,7 @@ export class Preview<T> extends Widget {
5758
this._id = options.id;
5859
this.codeSnippet = options.codeSnippet;
5960
this.editorServices = editorServices;
61+
this.codeSnippetService = CodeSnippetService.getCodeSnippetService();
6062
this.addClass(PREVIEW_CLASS);
6163
const layout = (this.layout = new PanelLayout());
6264
const content = new Panel();
@@ -157,9 +159,21 @@ export class Preview<T> extends Widget {
157159
const getMimeTypeByLanguage = this.editorServices.mimeTypeService
158160
.getMimeTypeByLanguage;
159161

162+
let previewFontSize = this.codeSnippetService.settings.get(
163+
'snippetPreviewFontSize'
164+
).composite as number;
165+
if (
166+
this.codeSnippetService.settings.get('snippetPreviewFontSize').user !==
167+
undefined
168+
) {
169+
previewFontSize = this.codeSnippetService.settings.get(
170+
'snippetPreviewFontSize'
171+
).user as number;
172+
}
173+
160174
this.editor = editorFactory({
161175
host: document.getElementById(PREVIEW_CONTENT + this._id),
162-
config: { readOnly: true, fontSize: 3 },
176+
config: { readOnly: true, fontSize: previewFontSize },
163177
model: new CodeEditor.Model({
164178
value: this.codeSnippet.code.join('\n'),
165179
mimeType: getMimeTypeByLanguage({

src/CodeSnippetService.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ export class CodeSnippetService {
6969

7070
this.codeSnippetList = userSnippets;
7171
}
72+
73+
if (this.settingManager.get('snippetPreviewFontSize').user === undefined) {
74+
this.settingManager.set(
75+
'snippetPreviewFontSize',
76+
this.settingManager.default('snippetPreviewFontSize')
77+
);
78+
}
7279
}
7380

7481
private convertToICodeSnippetList(snippets: JSONArray): ICodeSnippet[] {
@@ -90,6 +97,10 @@ export class CodeSnippetService {
9097
return this.codeSnippetService;
9198
}
9299

100+
get settings(): Settings {
101+
return this.settingManager;
102+
}
103+
93104
get snippets(): ICodeSnippet[] {
94105
return this.codeSnippetList;
95106
}

0 commit comments

Comments
 (0)