Completion: consider word separator

This commit is contained in:
Le Tan 2018-08-15 19:55:52 +08:00
parent 9a173168ff
commit 0508e8f34d
3 changed files with 49 additions and 3 deletions

View File

@ -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;
}

View File

@ -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() {}
}; };

View File

@ -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;
} }