Add spell-checking suggestions to the chat bar context menu
This is natively integrated into the existing chat document handler, and emulates normal Sonnet behavior.
This commit is contained in:
committed by
Tobias Fella
parent
6439fa48f9
commit
a4e6f0c4c2
@@ -90,6 +90,11 @@ public:
|
||||
}),
|
||||
mentions->end());
|
||||
}
|
||||
|
||||
QStringList suggestions(const QString &word) const
|
||||
{
|
||||
return checker->suggest(word);
|
||||
}
|
||||
};
|
||||
|
||||
ChatDocumentHandler::ChatDocumentHandler(QObject *parent)
|
||||
@@ -263,6 +268,47 @@ void ChatDocumentHandler::complete(int index)
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ChatDocumentHandler::getSuggestions(int mousePosition)
|
||||
{
|
||||
QTextCursor cursorAtMouse(document()->textDocument());
|
||||
cursorAtMouse.setPosition(mousePosition);
|
||||
|
||||
// Get the word under the (mouse-)cursor and see if it is misspelled.
|
||||
// Don't include apostrophes at the start/end of the word in the selection.
|
||||
QTextCursor wordSelectCursor(cursorAtMouse);
|
||||
wordSelectCursor.clearSelection();
|
||||
wordSelectCursor.select(QTextCursor::WordUnderCursor);
|
||||
m_selectedWord = wordSelectCursor.selectedText();
|
||||
|
||||
return m_highlighter->suggestions(m_selectedWord);
|
||||
}
|
||||
|
||||
bool ChatDocumentHandler::getActive() const
|
||||
{
|
||||
return m_highlighter->settings.checkerEnabledByDefault();
|
||||
}
|
||||
|
||||
bool ChatDocumentHandler::getIsWordIsMisspelled() const
|
||||
{
|
||||
return !m_highlighter->errors.isEmpty();
|
||||
}
|
||||
|
||||
QString ChatDocumentHandler::getWordUnderMouse() const
|
||||
{
|
||||
return m_selectedWord;
|
||||
}
|
||||
|
||||
void ChatDocumentHandler::replaceWord(const QString &word)
|
||||
{
|
||||
QTextCursor cursor(document()->textDocument());
|
||||
const auto &text = m_room->chatBoxText();
|
||||
|
||||
auto at = text.indexOf(m_highlighter->previousText);
|
||||
cursor.setPosition(at);
|
||||
cursor.setPosition(at + m_highlighter->previousText.length(), QTextCursor::KeepAnchor);
|
||||
cursor.insertText(word);
|
||||
}
|
||||
|
||||
CompletionModel *ChatDocumentHandler::completionModel() const
|
||||
{
|
||||
return m_completionModel;
|
||||
|
||||
Reference in New Issue
Block a user