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;
|
||||
}
|
||||
|
||||
// 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.
|
||||
static bool isEmptyBlock(const QTextBlock &p_block);
|
||||
|
||||
static bool isWordSeparator(QChar p_char);
|
||||
|
||||
private:
|
||||
VEditUtils() {}
|
||||
};
|
||||
|
@ -807,7 +807,7 @@ void VEditor::replaceText(const QString &p_text,
|
||||
QRegExp exp;
|
||||
if (useRegExp) {
|
||||
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,
|
||||
@ -855,7 +855,7 @@ void VEditor::replaceTextAll(const QString &p_text,
|
||||
QRegExp exp;
|
||||
if (useRegExp) {
|
||||
exp = QRegExp(p_text,
|
||||
p_options & FindOption::CaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||
(p_options & FindOption::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
||||
} else {
|
||||
newText = p_replaceText;
|
||||
}
|
||||
@ -1196,7 +1196,7 @@ QString VEditor::fetchCompletionPrefix() const
|
||||
QString prefix;
|
||||
while (pos >= blockPos) {
|
||||
QChar ch = m_document->characterAt(pos);
|
||||
if (ch.isSpace()) {
|
||||
if (ch.isSpace() || VEditUtils::isWordSeparator(ch)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user