Quellcode durchsuchen

Add `lineHeight` to the properties users can override.
Set property default values to `null`.
Use style from theme as default.

Raffaele De Feo vor 6 Jahren
Ursprung
Commit
27254c1979

+ 12 - 6
packages/codeeditor/src/editor.ts

@@ -562,14 +562,19 @@ namespace CodeEditor {
   export
   interface IConfig {
     /**
-     * The family of the font used in text editors.
+     * User preferred font family for text editors.
      */
-    fontFamily: string;
+    fontFamily: string | null;
 
     /**
-     * The size in pixel of the font used in text editors.
+     * User preferred size in pixel of the font used in text editors.
      */
-    fontSize: number;
+    fontSize: number | null;
+
+    /**
+     * User preferred text line height, as a multiplier of font size.
+     */
+    lineHeight: number | null;
 
     /**
      * Whether line numbers should be displayed.
@@ -612,8 +617,9 @@ namespace CodeEditor {
    */
   export
   let defaultConfig: IConfig = {
-    fontFamily: '\'Source Code Pro\', monospace',
-    fontSize: 13,
+    fontFamily: null,
+    fontSize: null,
+    lineHeight: null,
     lineNumbers: false,
     lineWrap: true,
     readOnly: false,

+ 17 - 4
packages/codemirror/src/editor.ts

@@ -1096,6 +1096,7 @@ namespace Private {
       fontFamily,
       fontSize,
       insertSpaces,
+      lineHeight,
       lineWrap,
       tabSize,
       readOnly,
@@ -1110,9 +1111,18 @@ namespace Private {
       ...otherOptions
     };
     return CodeMirror(el => {
-      el.style.fontFamily = fontFamily;
-      el.style.fontSize = fontSize + 'px';
-      el.classList.toggle(READ_ONLY_CLASS, readOnly);
+      if (fontFamily) {
+        el.style.fontFamily = fontFamily;
+      }
+      if (fontSize) {
+        el.style.fontSize = fontSize + 'px';
+      }
+      if (lineHeight) {
+        el.style.lineHeight = lineHeight.toString();
+      }
+      if (readOnly) {
+        el.classList.add(READ_ONLY_CLASS);
+      }
       host.appendChild(el);
     }, bareConfig);
   }
@@ -1205,7 +1215,10 @@ namespace Private {
       el.style.fontFamily = value;
       break;
     case 'fontSize':
-      el.style.fontSize = value + 'px';
+      el.style.fontSize = value ? value + 'px' : null;
+      break;
+    case 'lineHeight':
+      el.style.lineHeight = value ? value.toString() : null;
       break;
     default:
       editor.setOption(option, value);

+ 2 - 0
packages/codemirror/style/index.css

@@ -23,6 +23,8 @@
 
 .CodeMirror {
   line-height: var(--jp-code-line-height);
+  font-size: var(--jp-code-font-size);
+  font-family: var(--jp-code-font-family);
   height: auto;
   /* Changed to auto to autogrow */
 }

+ 10 - 4
packages/fileeditor-extension/schema/plugin.json

@@ -10,10 +10,15 @@
           "type": "boolean"
         },
         "fontFamily": {
-          "type": "string"
+          "type": ["string", "null"]
         },
         "fontSize": {
-          "type": "number"
+          "type": ["integer", "null"],
+          "minimum": 1,
+          "maximum": 100
+        },
+        "lineHeight": {
+          "type": ["number", "null"]
         },
         "lineNumbers": {
           "type": "boolean"
@@ -45,8 +50,9 @@
       "$ref": "#/definitions/editorConfig",
       "default": {
         "autoClosingBrackets": true,
-        "fontFamily": "'Source Code Pro', monospace",
-        "fontSize": 13,
+        "fontFamily": null,
+        "fontSize": null,
+        "lineHeight": null,
         "lineNumbers": true,
         "lineWrap": true,
         "matchBrackets": true,