Skip to content

fix(editor): sync rich text color toolbar state#382

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:bug-fix-6-24-1
Jun 24, 2026
Merged

fix(editor): sync rich text color toolbar state#382
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:bug-fix-6-24-1

Conversation

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member

Update the rich text toolbar color buttons from the current selection style.

选中已有文字时,根据当前选区样式同步字体颜色和高亮色按钮状态。

Read foreground and background colors from current editor style.

从当前编辑器样式中读取前景色和背景色。

Keep color icon display and palette selected state consistent with selected text.

保持颜色图标显示和调色板选中态与选中文字一致。

Log: 修复富文本工具栏颜色与编辑区选中文字颜色显示不一致
PMS: BUG-277431

Influence: 选中已有文字或高亮文字时,工具栏中的字体颜色和高亮色显示更准确;设置颜色和后续输入逻辑不受影响。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @dengzhongyuan365-dev, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/web/js/summernote_v9_2.js": [
        {
            "line": "    var KEY_BOGUS = 'bogus';",
            "line_number": 3933,
            "rule": "S106",
            "reason": "Var naming | 6d7db7168d"
        },
        {
            "line": "                    .attr('src', 'https://instagram.com/p/' + igMatch[1] + '/embed/')",
            "line_number": 6927,
            "rule": "S35",
            "reason": "Url link | dcb31e9ddf"
        },
        {
            "line": "                    .attr('src', 'http://v.qq.com/iframe/player.html?vid=' + vid + '&auto=0');",
            "line_number": 6964,
            "rule": "S35",
            "reason": "Url link | ce631f8419"
        }
    ]
}

Update the rich text toolbar color buttons from the current selection style.

选中已有文字时,根据当前选区样式同步字体颜色和高亮色按钮状态。

Read foreground and background colors from current editor style.

从当前编辑器样式中读取前景色和背景色。

Keep color icon display and palette selected state consistent with selected text.

保持颜色图标显示和调色板选中态与选中文字一致。

Log: 修复富文本工具栏颜色与编辑区选中文字颜色显示不一致
PMS: BUG-277431

Influence: 选中已有文字或高亮文字时,工具栏中的字体颜色和高亮色显示更准确;设置颜色和后续输入逻辑不受影响。
@github-actions

Copy link
Copy Markdown
  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/web/js/summernote_v9_2.js": [
        {
            "line": "    var KEY_BOGUS = 'bogus';",
            "line_number": 3933,
            "rule": "S106",
            "reason": "Var naming | 6d7db7168d"
        },
        {
            "line": "                    .attr('src', 'https://instagram.com/p/' + igMatch[1] + '/embed/')",
            "line_number": 6928,
            "rule": "S35",
            "reason": "Url link | dcb31e9ddf"
        },
        {
            "line": "                    .attr('src', 'http://v.qq.com/iframe/player.html?vid=' + vid + '&auto=0');",
            "line_number": 6965,
            "rule": "S35",
            "reason": "Url link | ce631f8419"
        }
    ]
}

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了富文本编辑器颜色按钮状态同步功能,逻辑严谨且无安全风险
四个审查维度均表现优异,完全符合优秀代码标准

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

代码在Style.prototype.fromNode中正确扩展了属性数组以提取颜色,新增的normalizeColor方法通过正则准确识别并统一了透明色及格式差异,updateCurrentColorButton方法利用jQuery的each循环正确查找匹配项并通过return false提前退出,整体逻辑严密无误
建议:在updateCurrentColorButton中可增加对normalizedColor为transparent的处理,使其能主动清除之前的高亮状态与预览样式,实现更完美的状态重置

  • 2.代码质量(良好)✓

新增功能采用了职责分离的设计,将颜色规范化与UI更新拆分为独立的prototype方法,提高了代码的可读性和可维护性,变量命名如normalizedColor、$matchedButton等语义清晰准确
建议:为新增的normalizeColor和updateCurrentColorButton方法补充JSDoc注释,说明参数含义及返回值,进一步提升可维护性

  • 3.代码性能(高效)✓

遍历颜色按钮的复杂度为O(N),由于工具栏颜色面板按钮数量固定且较少,正则匹配和DOM操作的开销微乎其微,不会引起任何性能瓶颈

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码从DOM计算样式中提取颜色值,经过严格的正则过滤和toLowerCase处理后,再通过jQuery的.css()和.attr()方法设置属性,jQuery底层会自动对传入值进行安全转义,有效阻断了潜在的CSS注入或XSS攻击面

  • 建议:继续保持对DOM外部输入的过滤与规范化习惯

■ 【改进建议代码示例】

Buttons.prototype.updateCurrentColorButton = function ($container, groupSelector, eventName, color) {
    var _this = this;
    var normalizedColor = this.normalizeColor(color);

    var $group = $container.find(groupSelector);
    if (!$group.length) {
        return;
    }

    var $matchedButton = $$1();
    var $colorBtns = $group.find('.note-color-btn');
    $colorBtns.each(function (idx, item) {
        var $item = $$1(item);
        if (_this.normalizeColor($item.attr('data-value')) === normalizedColor) {
            $matchedButton = $item;
            return false;
        }
    });

    $colorBtns.removeClass('selectColor');
    if ($matchedButton.length) {
        $matchedButton.addClass('selectColor');
    }

    var $currentButton = $group.find('.note-current-color-button');
    if (normalizedColor && normalizedColor !== 'transparent') {
        $currentButton.attr('data-' + eventName, normalizedColor);
        if (eventName === 'foreColor') {
            $group.find('.icon-forecolor .path1').css('color', normalizedColor);
        } else if (eventName === 'backColor') {
            $group.find('.icon-backcolor .path1').css('color', normalizedColor);
        }
    } else {
        $currentButton.removeAttr('data-' + eventName);
        if (eventName === 'foreColor') {
            $group.find('.icon-forecolor .path1').css('color', '');
        } else if (eventName === 'backColor') {
            $group.find('.icon-backcolor .path1').css('color', '');
        }
    }
};

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member Author

/forcemerge

@deepin-bot deepin-bot Bot merged commit 8ffda47 into linuxdeepin:develop/snipe Jun 24, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants