@@ -125,22 +125,30 @@ function buildDocText(item) {
125125 return doc . trim ( ) + '\n\n返回值:' + item . returns ;
126126}
127127
128- // 滚动+Ctrl放大或缩小代码
129- function ACE_ChangeCodeSize ( editor , currentFontSize , showToast ) {
128+ /**
129+ * 绑定 Ctrl + 滚轮事件以精细调整编辑器字体大小
130+ * @param {Object } editor - ACE 编辑器实例
131+ * @param {number } currentFontSize - 当前字体大小(单位:px)
132+ * @param {function } showToast - 显示提示信息的函数
133+ * @param {number } step - 每次缩放的步长(默认 1)
134+ */
135+ function ACE_ChangeCodeSize ( editor , currentFontSize , showToast , step = 1 ) {
136+ // 确保初始字体大小合法
137+ let fontSize = Math . max ( 8 , Math . min ( currentFontSize , 72 ) ) ;
130138 editor . container . addEventListener (
131139 'wheel' ,
132140 ( e ) => {
133141 if ( ! e . ctrlKey ) return ;
134142 e . preventDefault ( ) ;
135143 const delta = e . deltaY ;
136144 if ( delta < 0 ) {
137- currentFontSize = Math . min ( currentFontSize + 7 , 140 ) ;
138- showToast ( currentFontSize + 'px:' + ( currentFontSize / 14 ) * 100 + '%' ) ;
145+ fontSize = Math . min ( fontSize + step , 72 ) ;
139146 } else if ( delta > 0 ) {
140- currentFontSize = Math . max ( currentFontSize - 7 , 7 ) ;
141- showToast ( currentFontSize + 'px:' + ( currentFontSize / 14 ) * 100 + '%' ) ;
147+ fontSize = Math . max ( fontSize - step , 8 ) ;
142148 }
143- editor . setFontSize ( currentFontSize ) ;
149+ editor . setFontSize ( fontSize ) ;
150+ const percent = ( ( fontSize / 14 ) * 100 ) . toFixed ( 1 ) ;
151+ showToast ( ` ${ fontSize } px ( ${ percent } %)` ) ;
144152 } ,
145153 { passive : false } ,
146154 ) ;
0 commit comments