diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js
index 91e7683a4..a4d2278e2 100644
--- a/browser/components/CodeEditor.js
+++ b/browser/components/CodeEditor.js
@@ -11,10 +11,10 @@ import crypto from 'crypto'
import consts from 'browser/lib/consts'
import fs from 'fs'
const { ipcRenderer } = require('electron')
+import normalizeEditorFontFamily from 'browser/lib/normalizeEditorFontFamily'
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
-const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace']
const buildCMRulers = (rulers, enableRulers) =>
enableRulers ? rulers.map(ruler => ({column: ruler})) : []
@@ -495,10 +495,7 @@ export default class CodeEditor extends React.Component {
render () {
const {className, fontSize} = this.props
- let fontFamily = this.props.fontFamily
- fontFamily = _.isString(fontFamily) && fontFamily.length > 0
- ? [fontFamily].concat(defaultEditorFontFamily)
- : defaultEditorFontFamily
+ const fontFamily = normalizeEditorFontFamily(this.props.fontFamily)
const width = this.props.width
return (
0
+ ? [fontFamily].concat(defaultEditorFontFamily).join(', ')
+ : defaultEditorFontFamily.join(', ')
+}
diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js
index ce149f653..aa3568e71 100644
--- a/browser/main/modals/PreferencesModal/UiTab.js
+++ b/browser/main/modals/PreferencesModal/UiTab.js
@@ -11,6 +11,7 @@ import 'codemirror-mode-elixir'
import _ from 'lodash'
import i18n from 'browser/lib/i18n'
import { getLanguages } from 'browser/lib/Languages'
+import normalizeEditorFontFamily from 'browser/lib/normalizeEditorFontFamily'
const OSX = global.process.platform === 'darwin'
@@ -164,7 +165,7 @@ class UiTab extends React.Component {
const { config, codemirrorTheme } = this.state
const codemirrorSampleCode = 'function iamHappy (happy) {\n\tif (happy) {\n\t console.log("I am Happy!")\n\t} else {\n\t console.log("I am not Happy!")\n\t}\n};'
const enableEditRulersStyle = config.editor.enableRulers ? 'block' : 'none'
- const customCSS = config.preview.customCSS
+ const fontFamily = normalizeEditorFontFamily(config.editor.fontFamily)
return (
@@ -262,8 +263,16 @@ class UiTab extends React.Component {
})
}
-
-
(this.codeMirrorInstance = e)} value={codemirrorSampleCode} options={{ lineNumbers: true, readOnly: true, mode: 'javascript', theme: codemirrorTheme }} />
+
+ (this.codeMirrorInstance = e)}
+ value={codemirrorSampleCode}
+ options={{
+ lineNumbers: true,
+ readOnly: true,
+ mode: 'javascript',
+ theme: codemirrorTheme
+ }} />
@@ -596,7 +605,19 @@ class UiTab extends React.Component {
type='checkbox'
/>
{i18n.__('Allow custom CSS for preview')}
-
this.handleUIChange(e)} ref={e => (this.customCSSCM = e)} value={config.preview.customCSS} options={{ lineNumbers: true, mode: 'css', theme: codemirrorTheme }} />
+
+ this.handleUIChange(e)}
+ ref={e => (this.customCSSCM = e)}
+ value={config.preview.customCSS}
+ options={{
+ lineNumbers: true,
+ mode: 'css',
+ theme: codemirrorTheme
+ }} />
+
diff --git a/tests/lib/normalize-editor-font-family-test.js b/tests/lib/normalize-editor-font-family-test.js
new file mode 100644
index 000000000..aacd03acd
--- /dev/null
+++ b/tests/lib/normalize-editor-font-family-test.js
@@ -0,0 +1,16 @@
+/**
+ * @fileoverview Unit test for browser/lib/normalizeEditorFontFamily
+ */
+import test from 'ava'
+import normalizeEditorFontFamily from '../../browser/lib/normalizeEditorFontFamily'
+import consts from '../../browser/lib/consts'
+const defaultEditorFontFamily = consts.DEFAULT_EDITOR_FONT_FAMILY
+
+test('normalizeEditorFontFamily() should return default font family (string[])', t => {
+ t.is(normalizeEditorFontFamily(), defaultEditorFontFamily.join(', '))
+})
+
+test('normalizeEditorFontFamily(["hoge", "huga"]) should return default font family connected with arg.', t => {
+ const arg = 'font1, font2'
+ t.is(normalizeEditorFontFamily(arg), `${arg}, ${defaultEditorFontFamily.join(', ')}`)
+})