Skip to content

Commit 5572083

Browse files
committed
Added real-time font-size change inside the code editor preview, also moved font-size to the end of settings list since editor preview is rendering it in real time
1 parent 4b71ab9 commit 5572083

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/js/services/settings/editor-preview.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ export const handleEditorPreviewUpdates = () => {
4141
})()
4242

4343
if (null !== value) {
44-
editor?.setOption(opt, value)
44+
if ('font_size' === setting.name) {
45+
const codeElement = document.querySelector('.CodeMirror-code')
46+
if (codeElement && codeElement instanceof HTMLElement) {
47+
codeElement.style.fontSize = `${value}px`
48+
}
49+
} else {
50+
editor?.setOption(opt, value)
51+
}
4552
}
4653
})
4754
}

src/php/settings/settings-fields.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,6 @@ function get_settings_fields(): array {
162162
'codemirror' => 'indentUnit',
163163
'min' => 0,
164164
],
165-
'font_size' => [
166-
'name' => __( 'Font Size', 'code-snippets' ),
167-
'type' => 'number',
168-
'desc' => __( 'The font size for the code editor.', 'code-snippets' ),
169-
'label' => _x( 'px', 'unit', 'code-snippets' ),
170-
'codemirror' => 'fontSize',
171-
'min' => 8,
172-
'max' => 24,
173-
],
174165
'wrap_lines' => [
175166
'name' => __( 'Wrap Lines', 'code-snippets' ),
176167
'type' => 'checkbox',
@@ -225,6 +216,14 @@ function get_settings_fields(): array {
225216
'options' => get_editor_theme_list(),
226217
'codemirror' => 'theme',
227218
],
219+
'font_size' => [
220+
'name' => __( 'Code Editor Font Size', 'code-snippets' ),
221+
'type' => 'number',
222+
'label' => _x( 'px', 'unit', 'code-snippets' ),
223+
'codemirror' => 'fontSize',
224+
'min' => 8,
225+
'max' => 28,
226+
],
228227
];
229228

230229
$fields = apply_filters( 'code_snippets_settings_fields', $fields );

0 commit comments

Comments
 (0)