Skip to content

Commit 1ced6a2

Browse files
LiHua000deepin-bot[bot]
authored andcommitted
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
1 parent 84eb9ce commit 1ced6a2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/source/dialog/popupdialog.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,8 @@ int RenameDialog::showDialog(const QString &strReName, const QString &strAlias,
536536
if(m_lineEdit == NULL) {//创建DLineEdit,设定显示规则。
537537
m_lineEdit = new DLineEdit(this);
538538
//输入字符格式与文管保持一致
539-
connect(m_lineEdit, &DLineEdit::textChanged,[=](){
540-
QString name = "(^\\s+|[/\\\\:*\"'?<>|\r\n\t])";
539+
connect(m_lineEdit, &DLineEdit::textChanged, [=](){
541540
QString text = m_lineEdit->text();
542-
m_lineEdit->setText(text.remove(QRegularExpression(name)));
543541
if(m_nOkBtnIndex >= 0) { //重命名输入文字为空时确认按钮不可点击,输入文字后恢复
544542
if(text.isNull()||text.isEmpty()){
545543
getButton(m_nOkBtnIndex)->setEnabled(false);
@@ -548,6 +546,22 @@ int RenameDialog::showDialog(const QString &strReName, const QString &strAlias,
548546
}
549547
}
550548
});
549+
550+
// 失去焦点时,检查并清理非法字符
551+
connect(m_lineEdit->lineEdit(), &QLineEdit::editingFinished, [=](){
552+
QString name = "(^\\s+|[/\\\\:*\"'?<>|\r\n\t])";
553+
QRegularExpression regex(name);
554+
QLineEdit *lineEdit = m_lineEdit->lineEdit();
555+
QString text = lineEdit->text();
556+
557+
// 检查是否有非法字符
558+
if(regex.match(text).hasMatch() || text.startsWith(" ")) {
559+
QString cleanedText = text;
560+
cleanedText.remove(regex);
561+
562+
lineEdit->setText(cleanedText);
563+
}
564+
});
551565
}
552566
DLabel *strlabel = new DLabel;
553567
strlabel->setObjectName("ContentLabel");

0 commit comments

Comments
 (0)