From 4ed7d626d833ef44f0ef35ffdadd05a92b0958fd Mon Sep 17 00:00:00 2001 From: ZhangTingan Date: Tue, 23 Dec 2025 19:48:23 +0800 Subject: [PATCH] Fix: cursor jumping to end in rename dialog log: Validate input only on focus loss instead of on every keystroke. Bug:https://pms.uniontech.com/bug-view-345447.html --- src/source/dialog/popupdialog.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/source/dialog/popupdialog.cpp b/src/source/dialog/popupdialog.cpp index ef77a76b2..1f34d04bd 100644 --- a/src/source/dialog/popupdialog.cpp +++ b/src/source/dialog/popupdialog.cpp @@ -536,10 +536,8 @@ int RenameDialog::showDialog(const QString &strReName, const QString &strAlias, if(m_lineEdit == NULL) {//创建DLineEdit,设定显示规则。 m_lineEdit = new DLineEdit(this); //输入字符格式与文管保持一致 - connect(m_lineEdit, &DLineEdit::textChanged,[=](){ - QString name = "(^\\s+|[/\\\\:*\"'?<>|\r\n\t])"; + connect(m_lineEdit, &DLineEdit::textChanged, [=](){ QString text = m_lineEdit->text(); - m_lineEdit->setText(text.remove(QRegularExpression(name))); if(m_nOkBtnIndex >= 0) { //重命名输入文字为空时确认按钮不可点击,输入文字后恢复 if(text.isNull()||text.isEmpty()){ getButton(m_nOkBtnIndex)->setEnabled(false); @@ -548,6 +546,22 @@ int RenameDialog::showDialog(const QString &strReName, const QString &strAlias, } } }); + + // 失去焦点时,检查并清理非法字符 + connect(m_lineEdit->lineEdit(), &QLineEdit::editingFinished, [=](){ + QString name = "(^\\s+|[/\\\\:*\"'?<>|\r\n\t])"; + QRegularExpression regex(name); + QLineEdit *lineEdit = m_lineEdit->lineEdit(); + QString text = lineEdit->text(); + + // 检查是否有非法字符 + if(regex.match(text).hasMatch() || text.startsWith(" ")) { + QString cleanedText = text; + cleanedText.remove(regex); + + lineEdit->setText(cleanedText); + } + }); } DLabel *strlabel = new DLabel; strlabel->setObjectName("ContentLabel");