fix(editor): prevent floating toolbar from hiding on button click#349
Merged
pengfeixx merged 1 commit intoMay 28, 2026
Merged
Conversation
Use delayed hide (300ms) to avoid QML menu onClosed hiding the toolbar when a toolbar button is clicked. Also prevent default mousedown behavior to keep cursor position unchanged. 使用延迟隐藏(300ms)避免QML菜单关闭时误隐藏悬浮工具栏, 同时阻止mousedown默认行为保持光标位置不变。 Log: 修复悬浮工具栏点击按钮后立即消失的问题 PMS: BUG-361213 Influence: 修复后右键悬浮工具栏上的格式化按钮(加粗、斜体等) 可以正常点击,无选区时点击可切换后续输入的格式状态。
deepin pr auto review你好!我是CodeGeex。我已仔细审查了你提供的 不过,从语法逻辑、代码质量、性能和安全性角度来看,仍有以下可以改进的地方: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码及详细解释// 建议使用 IIFE (立即执行函数) 或模块作用域封装,避免污染全局变量
(function() {
// 常量提取,消除魔法数字。300ms 是经验值,给用户点击留出反应时间
const HIDE_TOOLBAR_DELAY = 300;
// 悬浮工具栏延迟隐藏定时器
let hideToolbarTimer = null;
// 监听悬浮工具栏按钮的mousedown事件
// 使用事件委托,注意这里的处理逻辑
$(document).on('mousedown', '.note-air-popover .note-btn', function(e) {
// 阻止浏览器默认行为,防止焦点从编辑区移开导致选区丢失
e.preventDefault();
// 清除延迟隐藏定时器
if (hideToolbarTimer) {
clearTimeout(hideToolbarTimer);
hideToolbarTimer = null;
}
});
// 右键隐藏悬浮工具栏(延迟执行)
window.hideRightMenu = function() { // 如果需要外部调用,可挂载到特定命名空间而非直接覆盖全局
if (hideToolbarTimer) {
clearTimeout(hideToolbarTimer);
}
hideToolbarTimer = setTimeout(function() {
// 防御性编程:确保 summernote 实例仍然存在
const $summernote = $('#summernote');
if ($summernote.length && $summernote.data('summernote')) {
try {
$summernote.summernote('airPopover.hide');
} catch (err) {
console.error('Failed to hide summernote airPopover:', err);
}
}
hideToolbarTimer = null;
}, HIDE_TOOLBAR_DELAY);
};
})();主要改进点说明:
额外建议:如果 |
lzwind
approved these changes
May 28, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use delayed hide (300ms) to avoid QML menu onClosed hiding the toolbar when a toolbar button is clicked. Also prevent default mousedown behavior to keep cursor position unchanged.
使用延迟隐藏(300ms)避免QML菜单关闭时误隐藏悬浮工具栏,
同时阻止mousedown默认行为保持光标位置不变。
Log: 修复悬浮工具栏点击按钮后立即消失的问题
PMS: BUG-361213
Influence: 修复后右键悬浮工具栏上的格式化按钮(加粗、斜体等)
可以正常点击,无选区时点击可切换后续输入的格式状态。