mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
Editor: refine completion in reverse case
Remove duplicates after reversing the list.
This commit is contained in:
parent
d27d20c4ea
commit
d014842bbf
@ -1504,7 +1504,7 @@ void VEditor::requestCompletion(bool p_reversed)
|
|||||||
cursor.clearSelection();
|
cursor.clearSelection();
|
||||||
setTextCursorW(cursor);
|
setTextCursorW(cursor);
|
||||||
|
|
||||||
QStringList words = generateCompletionCandidates();
|
QStringList words = generateCompletionCandidates(p_reversed);
|
||||||
QString prefix = fetchCompletionPrefix();
|
QString prefix = fetchCompletionPrefix();
|
||||||
// Smart case.
|
// Smart case.
|
||||||
Qt::CaseSensitivity cs = completionCaseSensitivity(prefix);
|
Qt::CaseSensitivity cs = completionCaseSensitivity(prefix);
|
||||||
@ -1526,7 +1526,7 @@ bool VEditor::isCompletionActivated() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList VEditor::generateCompletionCandidates() const
|
QStringList VEditor::generateCompletionCandidates(bool p_reversed) const
|
||||||
{
|
{
|
||||||
QString content = getContent();
|
QString content = getContent();
|
||||||
QTextCursor cursor = textCursorW();
|
QTextCursor cursor = textCursorW();
|
||||||
@ -1535,10 +1535,35 @@ QStringList VEditor::generateCompletionCandidates() const
|
|||||||
|
|
||||||
QRegExp reg("\\W+");
|
QRegExp reg("\\W+");
|
||||||
|
|
||||||
QStringList ret = content.mid(end).split(reg, QString::SkipEmptyParts);
|
QStringList above = content.left(start).split(reg, QString::SkipEmptyParts);
|
||||||
ret.append(content.left(start).split(reg, QString::SkipEmptyParts));
|
QStringList below = content.mid(end).split(reg, QString::SkipEmptyParts);
|
||||||
ret.removeDuplicates();
|
|
||||||
return ret;
|
if (p_reversed) {
|
||||||
|
QStringList rev;
|
||||||
|
rev.reserve(above.size() + below.size());
|
||||||
|
for (auto it = above.rbegin(); it != above.rend(); ++it) {
|
||||||
|
rev.append(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = below.rbegin(); it != below.rend(); ++it) {
|
||||||
|
rev.append(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
rev.removeDuplicates();
|
||||||
|
|
||||||
|
QStringList res;
|
||||||
|
res.reserve(rev.size());
|
||||||
|
for (auto it = rev.rbegin(); it != rev.rend(); ++it) {
|
||||||
|
res.append(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
// below + above.
|
||||||
|
below.append(above);
|
||||||
|
below.removeDuplicates();
|
||||||
|
return below;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VEditor::fetchCompletionPrefix() const
|
QString VEditor::fetchCompletionPrefix() const
|
||||||
|
@ -463,7 +463,7 @@ private:
|
|||||||
// Highlight @p_cursor as the searched keyword under cursor.
|
// Highlight @p_cursor as the searched keyword under cursor.
|
||||||
void highlightSearchedWordUnderCursor(const QTextCursor &p_cursor);
|
void highlightSearchedWordUnderCursor(const QTextCursor &p_cursor);
|
||||||
|
|
||||||
QStringList generateCompletionCandidates() const;
|
QStringList generateCompletionCandidates(bool p_reversed) const;
|
||||||
|
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user