Skip to content

Commit

Permalink
Spellchecker: on right click menu, check the spelling for the word un…
Browse files Browse the repository at this point in the history
…der the mouse instead of the word where the cursor is located; fix #1918 (#2551)
  • Loading branch information
ctrlaltca authored Aug 14, 2023
1 parent 4c100d5 commit de260e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/kvirc/ui/KviInputEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ KviInputEditor::KviInputEditor(QWidget * pPar, KviWindow * pWnd, KviUserListView
m_pInputParent = pPar;
m_iMaxBufferSize = KVI_INPUT_MAX_BUFFER_SIZE;
m_iCursorPosition = 0; //Index of the char AFTER the cursor
m_iSpellCheckPosition = 0; //Index of the char where spell checking is occuring
m_iSelectionBegin = -1; //Index of the first char in the selection
m_iSelectionEnd = -1; //Index of the last char in the selection
m_bIMComposing = false; //Whether the input method is active (composing).
Expand Down Expand Up @@ -1145,6 +1146,7 @@ void KviInputEditor::showContextPopup(const QPoint & pos)
std::vector<KviInputEditorSpellCheckerBlock *> lBuffer;
splitTextIntoSpellCheckerBlocks(m_szTextBuffer, lBuffer);

m_iSpellCheckPosition = std::min(charIndexFromXPosition(pos.x()), m_szTextBuffer.length());
KviInputEditorSpellCheckerBlock * pCurrentBlock = findSpellCheckerBlockAtCursor(lBuffer);

if(pCurrentBlock && pCurrentBlock->bSpellCheckable && (!pCurrentBlock->bCorrect))
Expand Down Expand Up @@ -1179,14 +1181,14 @@ void KviInputEditor::showContextPopup(const QPoint & pos)
// g_pInputPopup->addAction(imActions.at(i));
// }

g_pInputPopup->popup(pos);
g_pInputPopup->popup(mapToGlobal(pos));
}

void KviInputEditor::showContextPopupHere()
{
qreal fXPos = xPositionFromCharIndex(m_iCursorPosition);
int iBottom = heightHint() - KVI_INPUT_MARGIN - KVI_INPUT_XTRAPADDING; // not exact but easy
showContextPopup(mapToGlobal(QPoint(fXPos, iBottom)));
showContextPopup(QPoint(fXPos, iBottom));
}

KviInputEditorSpellCheckerBlock * KviInputEditor::findSpellCheckerBlockAtCursor(std::vector<KviInputEditorSpellCheckerBlock *> & lBlocks)
Expand All @@ -1195,7 +1197,7 @@ KviInputEditorSpellCheckerBlock * KviInputEditor::findSpellCheckerBlockAtCursor(

for(auto pBlock : lBlocks)
{
if(m_iCursorPosition <= (pBlock->iStart + pBlock->iLength))
if(m_iSpellCheckPosition <= (pBlock->iStart + pBlock->iLength))
{
pCurrentBlock = pBlock;
break;
Expand Down Expand Up @@ -1277,9 +1279,10 @@ void KviInputEditor::fillSpellCheckerCorrectionsPopup()

void KviInputEditor::showSpellCheckerCorrectionsPopup()
{
m_iSpellCheckPosition = m_iCursorPosition;
fillSpellCheckerCorrectionsPopup();

qreal fXPos = xPositionFromCharIndex(m_iCursorPosition);
qreal fXPos = xPositionFromCharIndex(m_iSpellCheckPosition);
if(fXPos > 24)
fXPos -= 24;

Expand Down Expand Up @@ -1333,7 +1336,7 @@ void KviInputEditor::mousePressEvent(QMouseEvent * e)

if(e->button() & Qt::RightButton)
{
showContextPopup(mapToGlobal(e->pos()));
showContextPopup(e->pos());
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/kvirc/ui/KviInputEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class KVIRC_API KviInputEditor : public QWidget
static int g_iCachedHeight;
QString m_szTextBuffer; // original buffer
int m_iCursorPosition;
int m_iSpellCheckPosition;
int m_iSelectionBegin;
int m_iSelectionEnd;
int m_iMaxBufferSize;
Expand Down

0 comments on commit de260e5

Please sign in to comment.