Skip to content

Commit ebf6f7e

Browse files
fix: Optimize mark removal logic in TextEdit and enhance file path handling 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
1 parent 8a992fd commit ebf6f7e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/editor/dtextedit.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "undolist.h"
1818
#include "changemarkcommand.h"
1919
#include "endlineformatcommond.h"
20+
#include <QSet>
2021

2122
#include <KSyntaxHighlighting/definition.h>
2223
#include <KSyntaxHighlighting/syntaxhighlighter.h>
@@ -6503,10 +6504,14 @@ void TextEdit::updateMark(int from, int charsRemoved, int charsAdded)
65036504
}
65046505

65056506
//从标记列表中移除标记
6506-
for (int j = 0; j < listRemoveItem.count(); j++) {
6507-
// 不应该-j
6508-
// m_wordMarkSelections.removeAt(listRemoveItem.value(j) - j);
6509-
m_wordMarkSelections.removeAt(listRemoveItem.value(j));
6507+
// 修复:使用removeIf避免索引管理问题
6508+
if (!listRemoveItem.isEmpty()) {
6509+
QSet<int> removeSet(listRemoveItem.begin(), listRemoveItem.end());
6510+
int index = 0;
6511+
int removedCount = m_wordMarkSelections.removeIf([&removeSet, &index](const auto&) {
6512+
return removeSet.contains(index++);
6513+
});
6514+
qDebug() << "updateMark: Removed" << removedCount << "marks, remaining:" << m_wordMarkSelections.size();
65106515
}
65116516
}
65126517

0 commit comments

Comments
 (0)