fix(editor): prevent main thread deadlock in selectTextInView - #494
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a re-entry guard around selectTextInView to prevent recursive re-entry and main-thread deadlock when performing select-all in fcitx5 environments, and adjusts build configuration to suppress debug output in Release builds and updates editor configuration defaults. Sequence diagram for re-entry guard in selectTextInViewsequenceDiagram
actor User
participant TextEdit
participant QInputMethod
participant fcitx5
participant ScrollBar
participant Layout
User->>TextEdit: selectTextInView
opt [m_isSelectingInView is false]
TextEdit->>TextEdit: selectTextInView
TextEdit->>TextEdit: setTextCursor
TextEdit->>QInputMethod: QInputMethod::update
QInputMethod->>fcitx5: queryCursorRect
fcitx5-->>ScrollBar: update scrollbar
fcitx5-->>Layout: update layout
ScrollBar->>TextEdit: slotValueChanged
Layout->>TextEdit: resizeEvent
TextEdit->>TextEdit: selectTextInView
end
opt [m_isSelectingInView is true]
TextEdit-->>TextEdit: return (re-entry blocked)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The re-entry guard in
selectTextInViewwould be more robust if implemented with a scoped helper (e.g. a small RAII object orQScopedValueRollback<bool>) so future early returns or added error paths can't accidentally leavem_isSelectingInViewstuck in thetruestate. - The
if(CMAKE_BUILD_TYPE STREQUAL "Release")condition is fragile for multi-config generators (e.g. VS, Xcode); consider using generator expressions like$<CONFIG:Release>or a cache option to controlQT_NO_DEBUG_OUTPUTinstead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The re-entry guard in `selectTextInView` would be more robust if implemented with a scoped helper (e.g. a small RAII object or `QScopedValueRollback<bool>`) so future early returns or added error paths can't accidentally leave `m_isSelectingInView` stuck in the `true` state.
- The `if(CMAKE_BUILD_TYPE STREQUAL "Release")` condition is fragile for multi-config generators (e.g. VS, Xcode); consider using generator expressions like `$<CONFIG:Release>` or a cache option to control `QT_NO_DEBUG_OUTPUT` instead.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Add re-entry guard to selectTextInView to break the self-excitation loop caused by setTextCursor triggering QInputMethod::update (fcitx5 async cursor query) and scrollbar/layout signals re-entering the function. 为 selectTextInView 添加重入守卫,阻断 setTextCursor 触发 QInputMethod::update(fcitx5 环境下异步回查光标矩形)及滚动条/布局 信号再次回调 selectTextInView 形成的自激振荡导致主线程死循环卡死。 同时 Release 构建禁用调试输出,调整默认主题资源路径。 Log: 修复全选时主线程死循环卡死问题 PMS: BUG-371465 Influence: 解决在 fcitx5 环境下执行视区内全选导致编辑器卡死的问题,同时优化 Release 构建输出与默认主题路径。
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 如果未来函数逻辑变得复杂,建议使用 RAII 管理状态
class ScopedFlag {
public:
ScopedFlag(bool& flag) : m_flag(flag) { m_flag = true; }
~ScopedFlag() { m_flag = false; }
private:
bool& m_flag;
};
void TextEdit::selectTextInView()
{
qDebug() << "Selecting text in view";
if (m_isSelectingInView) {
qDebug() << "Selecting text in view skipped: already in progress";
return;
}
ScopedFlag guard(m_isSelectingInView);
int startPos = cursorForPosition(QPoint(0, 0)).position();
QPoint endPoint = QPoint(this->viewport()->width(), this->viewport()->height());
int endPos = cursorForPosition(endPoint).position();
QTextCursor cursor = this->textCursor();
cursor.setPosition(startPos);
cursor.setPosition(startPos, QTextCursor::KeepAnchor);
this->setTextCursor(cursor);
this->horizontalScrollBar()->setValue(0);
qDebug() << "Selecting text in view completed";
} |
|
[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 |
|
/merge |
Add re-entry guard to selectTextInView to break the self-excitation loop caused by setTextCursor triggering QInputMethod::update (fcitx5 async cursor query) and scrollbar/layout signals re-entering the function.
为 selectTextInView 添加重入守卫,阻断 setTextCursor 触发
QInputMethod::update(fcitx5 环境下异步回查光标矩形)及滚动条/布局
信号再次回调 selectTextInView 形成的自激振荡导致主线程死循环卡死。
同时 Release 构建禁用调试输出,调整默认主题资源路径。
Log: 修复全选时主线程死循环卡死问题
PMS: BUG-371465
Influence: 解决在 fcitx5 环境下执行视区内全选导致编辑器卡死的问题,同时优化 Release 构建输出与默认主题路径。
Summary by Sourcery
Prevent editor main thread deadlock when selecting text in view and adjust release build behavior.
Bug Fixes:
Enhancements:
Build: