fix: Optimize mark removal logic in TextEdit and enhance file path ha…#384
Merged
Merged
Conversation
…ndling in Window - Refactored the mark removal process in TextEdit::updateMark to use QSet and removeIf, improving code clarity and reducing index management issues. log: Optimize mark removal logic and enhance file path handling bug: https://pms.uniontech.com/bug-view-331945.html
deepin pr auto review我对这段代码进行审查,并提出以下改进意见:
建议的进一步改进:
改进后的代码已经解决了原代码中的索引管理问题,并提高了代码的性能和可维护性。不过,建议在实际应用中根据具体需求进行测试,确保修改后的代码符合预期行为。 |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactor TextEdit::updateMark to leverage QSet and removeIf for mark removal, eliminating manual index adjustments and adding debug logging for removed and remaining marks. Class diagram for updated mark removal logic in TextEditclassDiagram
class TextEdit {
+void updateMark(int from, int charsRemoved, int charsAdded)
-QList<Selection> m_wordMarkSelections
}
class QSet {
+contains(int)
}
TextEdit --> QSet : uses for mark removal
TextEdit : updateMark now uses QSet and removeIf
TextEdit : m_wordMarkSelections.removeIf(predicate)
Flow diagram for optimized mark removal in updateMarkflowchart TD
A[Start updateMark] --> B[Identify marks to remove]
B --> C{Is listRemoveItem empty?}
C -- No --> D[Create QSet from listRemoveItem]
D --> E[Iterate m_wordMarkSelections with index]
E --> F[Remove selection if index in QSet]
F --> G[Count removed marks]
G --> H[Log removed and remaining marks]
C -- Yes --> I[Skip removal]
H --> J[End]
I --> J
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The PR description mentions file path handling enhancements in Window, but no related changes are included here—please add those updates or adjust the description to match.
- Consider replacing the raw qDebug() with a qCDebug() category (or guard it behind a verbosity flag) to avoid flooding logs in production builds.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The PR description mentions file path handling enhancements in Window, but no related changes are included here—please add those updates or adjust the description to match.
- Consider replacing the raw qDebug() with a qCDebug() category (or guard it behind a verbosity flag) to avoid flooding logs in production builds.
## Individual Comments
### Comment 1
<location> `src/editor/dtextedit.cpp:6514` </location>
<code_context>
+ int removedCount = m_wordMarkSelections.removeIf([&removeSet, &index](const auto&) {
+ return removeSet.contains(index++);
+ });
+ qDebug() << "updateMark: Removed" << removedCount << "marks, remaining:" << m_wordMarkSelections.size();
}
}
</code_context>
<issue_to_address>
Debug logging may be left in production code.
Consider removing or conditionally enabling this qDebug statement to avoid unnecessary log output and exposure of internal details in production.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
qDebug() << "updateMark: Removed" << removedCount << "marks, remaining:" << m_wordMarkSelections.size();
=======
#ifdef QT_DEBUG
qDebug() << "updateMark: Removed" << removedCount << "marks, remaining:" << m_wordMarkSelections.size();
#endif
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
lzwind
approved these changes
Sep 2, 2025
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind 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 |
Member
Author
|
/forcemerge |
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.
…ndling in Window
log: Optimize mark removal logic and enhance file path handling
bug: https://pms.uniontech.com/bug-view-331945.html
Summary by Sourcery
Refactor TextEdit::updateMark to simplify mark removal and avoid index mismanagement
Bug Fixes:
Enhancements: