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 | |||
| @@ -150,35 +150,37 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { | |||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) | 152 | void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event) |
| 153 | { | 153 | { |
| 154 | replaceWordActions_.clear(); | 154 | replaceWordActions_.clear(); |
| 155 | QAction* insertPoint = menu->actions().first(); | 155 | if (checker_ && highlighter_) { |
| 156 | QTextCursor cursor = cursorForPosition(event->pos()); | 156 | QAction* insertPoint = menu->actions().first(); |
| 157 | PositionPair wordPosition = getWordFromCursor(cursor.position()); | 157 | QTextCursor cursor = cursorForPosition(event->pos()); |
| 158 | if (boost::get<0>(wordPosition) < 0) { | 158 | PositionPair wordPosition = getWordFromCursor(cursor.position()); |
| 159 | // The click was executed outside a spellable word so no | 159 | if (boost::get<0>(wordPosition) < 0) { |
| 160 | // suggestions are necessary | 160 | // The click was executed outside a spellable word so no |
| 161 | return; | 161 | // suggestions are necessary |
| 162 | } | 162 | return; |
| 163 | cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); | 163 | } |
| 164 | cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); | 164 | cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); |
| 165 | std::vector<std::string> wordList; | 165 | cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor); |
| 166 | checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); | 166 | std::vector<std::string> wordList; |
| 167 | if (wordList.size() == 0) { | 167 | checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); |
| 168 | QAction* noSuggestions = new QAction(tr("No Suggestions"), menu); | 168 | if (wordList.size() == 0) { |
| 169 | noSuggestions->setDisabled(true); | 169 | QAction* noSuggestions = new QAction(tr("No Suggestions"), menu); |
| 170 | menu->insertAction(insertPoint, noSuggestions); | 170 | noSuggestions->setDisabled(true); |
| 171 | } | 171 | menu->insertAction(insertPoint, noSuggestions); |
| 172 | else { | ||
| 173 | for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { | ||
| 174 | QAction* wordAction = new QAction(it->c_str(), menu); | ||
| 175 | menu->insertAction(insertPoint, wordAction); | ||
| 176 | replaceWordActions_.push_back(wordAction); | ||
| 177 | } | 172 | } |
| 173 | else { | ||
| 174 | for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { | ||
| 175 | QAction* wordAction = new QAction(it->c_str(), menu); | ||
| 176 | menu->insertAction(insertPoint, wordAction); | ||
| 177 | replaceWordActions_.push_back(wordAction); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | menu->insertAction(insertPoint, menu->addSeparator()); | ||
| 178 | } | 181 | } |
| 179 | menu->insertAction(insertPoint, menu->addSeparator()); | ||
| 180 | } | 182 | } |
| 181 | 183 | ||
| 182 | 184 | ||
| 183 | #ifdef HAVE_SPELLCHECKER | 185 | #ifdef HAVE_SPELLCHECKER |
| 184 | void QtTextEdit::setUpSpellChecker() | 186 | void QtTextEdit::setUpSpellChecker() |
Swift