mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Completion: consider word separator
This commit is contained in:
parent
9a173168ff
commit
0508e8f34d
@ -1039,3 +1039,47 @@ bool VEditUtils::isEmptyBlock(const QTextBlock &p_block)
|
|||||||
{
|
{
|
||||||
return p_block.length() == 1;
|
return p_block.length() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy from QTextEngine::atWordSeparator(int position).
|
||||||
|
bool VEditUtils::isWordSeparator(QChar p_char)
|
||||||
|
{
|
||||||
|
switch (p_char.unicode()) {
|
||||||
|
case '.':
|
||||||
|
case ',':
|
||||||
|
case '?':
|
||||||
|
case '!':
|
||||||
|
case '@':
|
||||||
|
case '#':
|
||||||
|
case '$':
|
||||||
|
case ':':
|
||||||
|
case ';':
|
||||||
|
case '-':
|
||||||
|
case '<':
|
||||||
|
case '>':
|
||||||
|
case '[':
|
||||||
|
case ']':
|
||||||
|
case '(':
|
||||||
|
case ')':
|
||||||
|
case '{':
|
||||||
|
case '}':
|
||||||
|
case '=':
|
||||||
|
case '/':
|
||||||
|
case '+':
|
||||||
|
case '%':
|
||||||
|
case '&':
|
||||||
|
case '^':
|
||||||
|
case '*':
|
||||||
|
case '\'':
|
||||||
|
case '"':
|
||||||
|
case '`':
|
||||||
|
case '~':
|
||||||
|
case '|':
|
||||||
|
case '\\':
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -209,6 +209,8 @@ public:
|
|||||||
// Whether @p_block is empty.
|
// Whether @p_block is empty.
|
||||||
static bool isEmptyBlock(const QTextBlock &p_block);
|
static bool isEmptyBlock(const QTextBlock &p_block);
|
||||||
|
|
||||||
|
static bool isWordSeparator(QChar p_char);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VEditUtils() {}
|
VEditUtils() {}
|
||||||
};
|
};
|
||||||
|
@ -807,7 +807,7 @@ void VEditor::replaceText(const QString &p_text,
|
|||||||
QRegExp exp;
|
QRegExp exp;
|
||||||
if (useRegExp) {
|
if (useRegExp) {
|
||||||
exp = QRegExp(p_text,
|
exp = QRegExp(p_text,
|
||||||
p_options & FindOption::CaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
(p_options & FindOption::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool found = findTextHelper(p_text,
|
bool found = findTextHelper(p_text,
|
||||||
@ -855,7 +855,7 @@ void VEditor::replaceTextAll(const QString &p_text,
|
|||||||
QRegExp exp;
|
QRegExp exp;
|
||||||
if (useRegExp) {
|
if (useRegExp) {
|
||||||
exp = QRegExp(p_text,
|
exp = QRegExp(p_text,
|
||||||
p_options & FindOption::CaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
(p_options & FindOption::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||||
} else {
|
} else {
|
||||||
newText = p_replaceText;
|
newText = p_replaceText;
|
||||||
}
|
}
|
||||||
@ -1196,7 +1196,7 @@ QString VEditor::fetchCompletionPrefix() const
|
|||||||
QString prefix;
|
QString prefix;
|
||||||
while (pos >= blockPos) {
|
while (pos >= blockPos) {
|
||||||
QChar ch = m_document->characterAt(pos);
|
QChar ch = m_document->characterAt(pos);
|
||||||
if (ch.isSpace()) {
|
if (ch.isSpace() || VEditUtils::isWordSeparator(ch)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user