Fix: cursor jumping to end in rename dialog#337
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom Dec 25, 2025
Merged
Fix: cursor jumping to end in rename dialog#337deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
Conversation
log: Validate input only on focus loss instead of on every keystroke. Bug:https://pms.uniontech.com/bug-view-345447.html
deepin pr auto review我来对这个diff进行代码审查:
改进后的代码建议: class RenameDialog {
private:
static const QString INVALID_CHARS_REGEX; // 定义为类静态常量
static const QRegularExpression INVALID_CHARS_PATTERN;
};
const QString RenameDialog::INVALID_CHARS_REGEX = "(^\\s+|[/\\\\:*\"'?<>|\r\n\t])";
const QRegularExpression RenameDialog::INVALID_CHARS_PATTERN(INVALID_CHARS_REGEX);
// 在showDialog中:
connect(m_lineEdit, &DLineEdit::textChanged, [=](){
QString text = m_lineEdit->text();
if(m_nOkBtnIndex >= 0) {
getButton(m_nOkBtnIndex)->setEnabled(!text.isEmpty());
}
});
connect(m_lineEdit->lineEdit(), &QLineEdit::editingFinished, [=](){
QLineEdit *lineEdit = m_lineEdit->lineEdit();
if (!lineEdit) return; // 安全性检查
QString text = lineEdit->text();
if(INVALID_CHARS_PATTERN.match(text).hasMatch() || text.startsWith(" ")) {
lineEdit->setText(text.remove(INVALID_CHARS_PATTERN));
}
});这样的改进:
|
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts rename dialog validation so illegal characters are stripped only when editing finishes (focus loss), preventing the cursor from jumping to the end while still disabling the OK button on empty input. Sequence diagram for rename dialog text validation on focus losssequenceDiagram
actor User
participant RenameDialog
participant DLineEdit
participant QLineEdit
participant OkButton
User->>RenameDialog: Open rename dialog
RenameDialog->>DLineEdit: create m_lineEdit
DLineEdit->>QLineEdit: create internal lineEdit
RenameDialog->>DLineEdit: connect textChanged
RenameDialog->>QLineEdit: connect editingFinished
User->>QLineEdit: Type characters
QLineEdit-->>DLineEdit: textChanged(text)
DLineEdit-->>RenameDialog: textChanged(text)
RenameDialog->>RenameDialog: Check if text is empty
alt text is empty
RenameDialog->>OkButton: setEnabled(false)
else text is not empty
RenameDialog->>OkButton: setEnabled(true)
end
User->>QLineEdit: Change focus (finish editing)
QLineEdit-->>RenameDialog: editingFinished()
RenameDialog->>RenameDialog: Validate text with regex
alt text contains illegal characters or starts with space
RenameDialog->>QLineEdit: setText(cleanedText)
else text is valid
Note over RenameDialog,QLineEdit: Text remains unchanged
end
Class diagram for updated rename dialog validation logicclassDiagram
class RenameDialog {
- DLineEdit* m_lineEdit
- int m_nOkBtnIndex
+ int showDialog(QString strReName, QString strAlias, QWidget* parent)
}
class DLineEdit {
+ QLineEdit* lineEdit()
+ signal textChanged(QString text)
}
class QLineEdit {
+ QString text()
+ void setText(QString text)
+ signal textChanged(QString text)
+ signal editingFinished()
}
class DButton {
+ void setEnabled(bool enabled)
}
RenameDialog *-- DLineEdit : owns
DLineEdit *-- QLineEdit : wraps
RenameDialog --> QLineEdit : uses for validation
RenameDialog --> DButton : controls enabled state
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 regular expression pattern for invalid characters is now duplicated between the
textChangedandeditingFinishedhandlers; consider extracting it into a shared constant or helper to keep the logic in sync. - The explicit
text.startsWith(" ")check appears redundant given the(^\s+...)part of the regex already matches leading whitespace; you can likely simplify the condition to only rely on the regex match. - When updating the line edit text on
editingFinished, consider whether you need to preserve the cursor position/selection, as callingsetTextresets it and may affect UX if focus returns to the field.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The regular expression pattern for invalid characters is now duplicated between the `textChanged` and `editingFinished` handlers; consider extracting it into a shared constant or helper to keep the logic in sync.
- The explicit `text.startsWith(" ")` check appears redundant given the `(^\s+...)` part of the regex already matches leading whitespace; you can likely simplify the condition to only rely on the regex match.
- When updating the line edit text on `editingFinished`, consider whether you need to preserve the cursor position/selection, as calling `setText` resets it and may affect UX if focus returns to the field.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
max-lvs
approved these changes
Dec 25, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: LiHua000, max-lvs 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 |
Contributor
Author
|
/merge |
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.
log: Validate input only on focus loss instead of on every keystroke.
Bug:https://pms.uniontech.com/bug-view-345447.html
Summary by Sourcery
Adjust rename dialog input handling to validate and clean illegal characters only after editing is finished, preventing cursor position issues during typing while keeping confirmation button state tied to non-empty input.
Bug Fixes:
Enhancements: