From d2f1d657b486dc2c8ea006f4d7c9012a714ebf8d Mon Sep 17 00:00:00 2001 From: majiuping Date: Thu, 30 Jul 2026 20:03:31 +0800 Subject: [PATCH] fix(editor): gray out voice reading menu when no text is selected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Text to Speech" right-click menu item enablement logic had a mismatch between the normal path and the error-handling paths in TextEdit::popRightMenu(). The normal path checks hasSelection(), but both the DBus-failure branch and the no-audio-device branch bypassed this check, unconditionally calling setEnabled(true) — so the menu stayed enabled even with no text selected. The fix preserves the text-selection check in the error branches: when DBus fails or no audio device is present, the action is only enabled if the user has actually selected text (or has a column selection). slotVoiceReadingAction() already handles the unavailable service gracefully with a user-facing message. Log: 修复杀掉uos ai进程后,未选中文字时右键菜单"语音朗读"未置灰的问题 Bug: https://pms.uniontech.com/bug-view-372251.html --- src/editor/dtextedit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editor/dtextedit.cpp b/src/editor/dtextedit.cpp index 6f1ec75d..18093729 100644 --- a/src/editor/dtextedit.cpp +++ b/src/editor/dtextedit.cpp @@ -567,11 +567,11 @@ void TextEdit::popRightMenu(QPoint pos) } } else { qWarning() << __func__ << "DBUS getTTSEnable failed"; - m_voiceReadingAction->setEnabled(true); + m_voiceReadingAction->setEnabled(textCursor().hasSelection() || m_hasColumnSelection); } } else { qWarning() << __func__ << "No audio output device was detected."; - m_voiceReadingAction->setEnabled(true); + m_voiceReadingAction->setEnabled(textCursor().hasSelection() || m_hasColumnSelection); } m_rightMenu->addAction(m_dictationAction);