diff options
author | Tobias Markmann <tm@ayena.de> | 2015-07-13 10:57:57 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2015-07-13 10:57:57 (GMT) |
commit | cb8a1c43ff96c1d82c8ba1d30e210135303bbe26 (patch) | |
tree | d0506790ae72be27b2642bd4a2924c3bd43dc7aa /Swift | |
parent | c1c1b887ace33ae65a8b6ea00ca1d100c49e024a (diff) | |
download | swift-cb8a1c43ff96c1d82c8ba1d30e210135303bbe26.zip swift-cb8a1c43ff96c1d82c8ba1d30e210135303bbe26.tar.bz2 |
Fix Swift crash during start because of spellcheck code
Check that checker_ and highlighter_ are initialized before
calling them.
A crash report indicated a crash calling getMisspelledPositions()
on highlighter_ from QtTextEdit::contextMenuEvent(). This fix
should prevent this call to cause a crash.
Test-Information:
Verified that spell checking still works on OS X.
Change-Id: Idae37c1f9e2d1a0d0f64da251aa6778f2e9b47a2
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index fed8819..79a9474 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -152,31 +152,33 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) { replaceWordActions_.clear(); - QAction* insertPoint = menu->actions().first(); - QTextCursor cursor = cursorForPosition(event->pos()); - PositionPair wordPosition = getWordFromCursor(cursor.position()); - if (boost::get<0>(wordPosition) < 0) { - // The click was executed outside a spellable word so no - // suggestions are necessary - return; - } - cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); - cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); - std::vector<std::string> wordList; - checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); - if (wordList.size() == 0) { - QAction* noSuggestions = new QAction(tr("No Suggestions"), menu); - noSuggestions->setDisabled(true); - menu->insertAction(insertPoint, noSuggestions); - } - else { - for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { - QAction* wordAction = new QAction(it->c_str(), menu); - menu->insertAction(insertPoint, wordAction); - replaceWordActions_.push_back(wordAction); + if (checker_ && highlighter_) { + QAction* insertPoint = menu->actions().first(); + QTextCursor cursor = cursorForPosition(event->pos()); + PositionPair wordPosition = getWordFromCursor(cursor.position()); + if (boost::get<0>(wordPosition) < 0) { + // The click was executed outside a spellable word so no + // suggestions are necessary + return; + } + cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); + cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); + std::vector<std::string> wordList; + checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); + if (wordList.size() == 0) { + QAction* noSuggestions = new QAction(tr("No Suggestions"), menu); + noSuggestions->setDisabled(true); + menu->insertAction(insertPoint, noSuggestions); } + else { + for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { + QAction* wordAction = new QAction(it->c_str(), menu); + menu->insertAction(insertPoint, wordAction); + replaceWordActions_.push_back(wordAction); + } + } + menu->insertAction(insertPoint, menu->addSeparator()); } - menu->insertAction(insertPoint, menu->addSeparator()); } |