Completion: bug fix when cursor is at the end of a word

This commit is contained in:
Le Tan 2018-08-30 20:15:56 +08:00
parent 74ec3884d0
commit 3f5ccf6b6e
3 changed files with 13 additions and 5 deletions

View File

@ -919,14 +919,21 @@ void VEditUtils::insertTitleMark(QTextCursor &p_cursor,
void VEditUtils::findCurrentWord(QTextCursor p_cursor,
int &p_start,
int &p_end)
int &p_end,
bool p_findPrecedingWord)
{
QString text = p_cursor.block().text();
int pib = p_cursor.positionInBlock();
if (pib < text.size() && text[pib].isSpace()) {
p_start = p_end = p_cursor.position();
return;
if (!p_findPrecedingWord
|| pib == 0
|| text[pib - 1].isSpace()) {
p_start = p_end = p_cursor.position();
return;
}
p_cursor.movePosition(QTextCursor::PreviousCharacter);
}
p_cursor.movePosition(QTextCursor::StartOfWord);

View File

@ -182,7 +182,8 @@ public:
// @p_start will equals to @p_end if @p_cursor is a space.
static void findCurrentWord(QTextCursor p_cursor,
int &p_start,
int &p_end);
int &p_end,
bool p_findPrecedingWord = false);
// Find the start and end of the WORD @p_cursor locates in (within a single block).
// @p_start and @p_end will be the global position of the start and end of the WORD.

View File

@ -1187,7 +1187,7 @@ QStringList VEditor::generateCompletionCandidates() const
QString content = getContent();
QTextCursor cursor = textCursorW();
int start, end;
VEditUtils::findCurrentWord(cursor, start, end);
VEditUtils::findCurrentWord(cursor, start, end, true);
QRegExp reg("\\W+");