mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Completion: bug fix when cursor is at the end of a word
This commit is contained in:
parent
74ec3884d0
commit
3f5ccf6b6e
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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+");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user