@@ -29,7 +29,7 @@ import { Settings } from './common/settings.js';
2929import { CONNTYPE } from './constants.js' ;
3030import './layout.js' ; // load for side effects only
3131import { setupPlotterChart } from "./common/plotter.js" ;
32- import { mainContent , showSerial } from './layout.js' ;
32+ import { mainContent , showSerial , refitTerminal } from './layout.js' ;
3333import { registerPWA } from "./common/pwa.js" ;
3434
3535registerPWA ( ) ;
@@ -68,6 +68,10 @@ const messageDialog = new MessageModal("message");
6868const connectionType = new ButtonValueDialog ( "connection-type" ) ;
6969const settings = new Settings ( ) ;
7070
71+ const DEFAULT_EDITOR_FONT_SIZE = 16 ;
72+ const MIN_EDITOR_FONT_SIZE = 8 ;
73+ const MAX_EDITOR_FONT_SIZE = 48 ;
74+
7175// localStorage key used to remember the most recently chosen backend
7276// ("web" | "ble" | "usb"). When the user clicks Connect after a
7377// disconnect, we prefer the last backend over re-prompting for one.
@@ -97,6 +101,23 @@ function rememberLastBackend(workflowType) {
97101}
98102
99103const editorTheme = EditorView . theme ( { } , { dark : getCssVar ( 'editor-theme-dark' ) . trim ( ) === '1' } ) ;
104+ const editorFontSizeCompartment = new Compartment ( ) ;
105+
106+ function getEditorFontSize ( ) {
107+ const fontSize = Number . parseInt ( settings . getSetting ( 'editorFontSize' ) , 10 ) ;
108+ if ( Number . isNaN ( fontSize ) ) {
109+ return DEFAULT_EDITOR_FONT_SIZE ;
110+ }
111+ return Math . min ( Math . max ( fontSize , MIN_EDITOR_FONT_SIZE ) , MAX_EDITOR_FONT_SIZE ) ;
112+ }
113+
114+ function editorFontSizeTheme ( ) {
115+ return EditorView . theme ( {
116+ "&" : {
117+ fontSize : `${ getEditorFontSize ( ) } px` ,
118+ } ,
119+ } ) ;
120+ }
100121
101122// Map file extensions to a CodeMirror 6 language extension factory.
102123// Anything not in this map falls back to plain text (no language plugin).
@@ -655,6 +676,7 @@ const baseEditorExtensions = [
655676 keymap . of ( hotkeyMap ) ,
656677 indentUnit . of ( " " ) ,
657678 editorTheme ,
679+ editorFontSizeCompartment . of ( editorFontSizeTheme ( ) ) ,
658680 syntaxHighlighting ( classHighlighter ) ,
659681 EditorView . updateListener . of ( onTextChange )
660682] ;
@@ -939,6 +961,7 @@ function getCssVar(varName) {
939961
940962async function setupXterm ( ) {
941963 state . terminal = new Terminal ( {
964+ fontSize : getEditorFontSize ( ) ,
942965 theme : {
943966 background : getCssVar ( 'background-color' ) ,
944967 foreground : getCssVar ( 'terminal-text-color' ) ,
@@ -999,13 +1022,18 @@ function applySettings() {
9991022
10001023 // Apply to EditorView.theme dark parameter
10011024 editor . darkTheme = getCssVar ( 'editor-theme-dark' ) . trim ( ) === '1' ;
1025+ editor . dispatch ( {
1026+ effects : editorFontSizeCompartment . reconfigure ( editorFontSizeTheme ( ) ) ,
1027+ } ) ;
10021028
10031029 // Apply to xterm
10041030 state . terminal . options . theme = {
10051031 background : getCssVar ( 'background-color' ) ,
10061032 foreground : getCssVar ( 'terminal-text-color' ) ,
10071033 cursor : getCssVar ( 'terminal-text-color' ) ,
10081034 } ;
1035+ state . terminal . options . fontSize = getEditorFontSize ( ) ;
1036+ refitTerminal ( ) ;
10091037
10101038 debugMessageAnsi = null ;
10111039
0 commit comments