From 4ab42b274ab5b369a3713b5a55e9f5074a599f68 Mon Sep 17 00:00:00 2001 From: Hermes Date: Mon, 20 Apr 2026 21:00:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(color-picker):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E5=8F=82=E6=95=B0=E5=9B=9E=E5=86=99=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: Rhino JS 闭包中局部变量捕获异常,onSelect 回调无法访问 inputShortXIconTint 修复: - 将输入框引用存储到 self.state._btnEditorTintInput,绕过闭包问题 - onSelect 回调从 self.state 读取输入框,同时直接更新 targetBtn.iconTint 作为双保险 - 保存按钮优先使用 targetBtn.iconTint,回退到输入框 getValue() --- code/th_14_panels.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/code/th_14_panels.js b/code/th_14_panels.js index bb6c5cc..f0515d5 100644 --- a/code/th_14_panels.js +++ b/code/th_14_panels.js @@ -935,10 +935,15 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { onSelect: function(colorHex) { try { var safeColor = String(colorHex || ""); - if (inputShortXIconTint && inputShortXIconTint.input) { - inputShortXIconTint.input.setText(safeColor); - try { inputShortXIconTint.input.invalidate(); } catch(e) {} + // # 避免 Rhino 闭包问题:从 self.state 读取输入框引用 + var tintInput = self.state._btnEditorTintInput || inputShortXIconTint; + if (tintInput && tintInput.input) { + tintInput.input.setText(safeColor); + try { tintInput.input.invalidate(); } catch(e) {} } + // # 双保险:直接更新 targetBtn,确保保存时能拿到正确值 + if (safeColor) targetBtn.iconTint = safeColor; + else delete targetBtn.iconTint; try { if (tintPaletteState.toggleBtn) tintPaletteState.toggleBtn.setText(safeColor || "\u9009\u62e9\u989c\u8272"); } catch(e) {} } catch(eSelect) { safeLog(self.L, 'e', "colorPicker callback err=" + String(eSelect)); @@ -1254,6 +1259,8 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { var defaultTint = targetBtn.iconTint ? String(targetBtn.iconTint) : ""; var inputShortXIconTint = self.ui.createInputGroup(self, "图标颜色 (留空跟随主题)", defaultTint, false, "支持 #RRGGBB / #AARRGGBB;下方可展开完整调色板"); form.addView(inputShortXIconTint.view); + // # 避免 Rhino 闭包问题:将输入框引用存储到 self.state,供颜色选择器回调使用 + self.state._btnEditorTintInput = inputShortXIconTint; function updateTintPaletteToggleText() { try { @@ -1499,10 +1506,15 @@ FloatBallAppWM.prototype.buildButtonEditorPanelView = function() { onSelect: function(colorHex) { try { var safeColor = String(colorHex || ""); - if (inputShortXIconTint && inputShortXIconTint.input) { - inputShortXIconTint.input.setText(safeColor); - try { inputShortXIconTint.input.invalidate(); } catch(e) {} + // # 避免 Rhino 闭包问题:从 self.state 读取输入框引用 + var tintInput = self.state._btnEditorTintInput || inputShortXIconTint; + if (tintInput && tintInput.input) { + tintInput.input.setText(safeColor); + try { tintInput.input.invalidate(); } catch(e) {} } + // # 双保险:直接更新 targetBtn,确保保存时能拿到正确值 + if (safeColor) targetBtn.iconTint = safeColor; + else delete targetBtn.iconTint; try { if (tintPaletteState.toggleBtn) tintPaletteState.toggleBtn.setText(safeColor || "\u9009\u62e9\u989c\u8272"); } catch(e) {} } catch(eSelect) { safeLog(self.L, 'e', "colorPicker callback err=" + String(eSelect)); @@ -3314,8 +3326,11 @@ shortcutWrap.addView(scBody); } else { var sxIcon = self.normalizeShortXIconName(currentShortXIconName, false); if (sxIcon) newBtn.iconResName = sxIcon; else delete newBtn.iconResName; - // 保存 ShortX 图标颜色 - var sxTint = inputShortXIconTint.getValue(); + // # 保存 ShortX 图标颜色:优先使用 targetBtn.iconTint(颜色选择器已更新),回退到输入框 + var sxTint = targetBtn.iconTint || ""; + if (!sxTint) { + try { sxTint = inputShortXIconTint.getValue(); } catch(eGetTint) {} + } if (sxTint && sxTint.length > 0) newBtn.iconTint = sxTint; else delete newBtn.iconTint; delete newBtn.iconPath; // 清除文件路径 }