Skip to content

Commit 8dbee02

Browse files
committed
更细致的代码大小设置
1 parent 6b044ce commit 8dbee02

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

iframe/script/User_config/ACE_Config.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)