Commit ad0f72a5 authored by Shreya Pandit's avatar Shreya Pandit

Correct spellchecking for words with apostrophe: Bug 291469

parent a186697c
......@@ -2,6 +2,7 @@
* Copyright (C) 2007, 2008 Fredy Yanardi <fyanardi@gmail.com>
* Copyright (C) 2007,2009,2010 Thomas Zander <zander@kde.org>
* Copyright (C) 2010 Christoph Goerlich <chgoerlich@gmx.de>
* Copyright (C) 2012 Shreya Pandit <shreya@shreyapandit.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -373,7 +374,7 @@ void SpellCheck::setCurrentCursorPosition(const QTextDocument *document, int cur
&& cursorPosition <= block.position() + range.start + range.length
&& range.format == m_defaultMisspelledFormat) {
QString word = block.text().mid(range.start, range.length);
m_spellCheckMenu->setMisspelled(word, block.position() + range.start);
m_spellCheckMenu->setMisspelled(word, block.position() + range.start,range.length);
m_spellCheckMenu->setCurrentLanguage(m_bgSpellCheck->currentLanguage());
m_spellCheckMenu->setVisible(true);
m_spellCheckMenu->setEnabled(true);
......@@ -413,7 +414,7 @@ void SpellCheck::clearHighlightMisspelled(int startPosition)
}
}
void SpellCheck::replaceWordBySuggestion(const QString &word, int startPosition)
void SpellCheck::replaceWordBySuggestion(const QString &word, int startPosition, int lengthOfWord)
{
if (!m_document)
return;
......@@ -422,9 +423,11 @@ void SpellCheck::replaceWordBySuggestion(const QString &word, int startPosition)
if (!block.isValid())
return;
int i=0;
QTextCursor cursor(m_document);
cursor.setPosition(startPosition);
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
cursor.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor, lengthOfWord);
cursor.removeSelectedText();
//if the replaced word and the suggestion had the same number of chars,
//we must clear highlighting manually, see 'documentChanged'
if ((cursor.selectionEnd() - cursor.selectionStart()) == word.length())
......
......@@ -2,6 +2,7 @@
* Copyright (C) 2007 Fredy Yanardi <fyanardi@gmail.com>
* Copyright (C) 2007,2010 Thomas Zander <zander@kde.org>
* Copyright (C) 2010 Christoph Goerlich <chgoerlich@gmx.de>
* Copyright (C) 2012 Shreya Pandit <shreya@shreyapandit.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -30,8 +31,10 @@
#include <QPointer>
#include <QQueue>
#include <QTextLayout>
#include <QTextStream>
class QTextDocument;
class QTextStream;
class BgSpellCheck;
class SpellCheckMenu;
......@@ -67,7 +70,7 @@ public:
//reimplemented from Calligra2.0, we disconnect and re- connect the 'documentChanged' signal only when the document has replaced
void setDocument(const QTextDocument *document);
void replaceWordBySuggestion(const QString &word, int startPosition);
void replaceWordBySuggestion(const QString &word, int startPosition,int lengthOfWord);
public slots:
void setDefaultLanguage(const QString &lang);
......@@ -102,6 +105,8 @@ private:
bool m_allowSignals;
bool m_documentIsLoading;
bool m_isChecking;
QTextStream stream;
int position;
QTextCharFormat m_defaultMisspelledFormat;
SpellCheckMenu *m_spellCheckMenu;
......
/* This file is part of the KDE project
* Copyright (C) 2010 Christoph Goerlich <chgoerlich@gmx.de>
* Copyright (C) 2012 Shreya Pandit <shreya@shreyapandit.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -111,9 +112,10 @@ void SpellCheckMenu::addWordToDictionary()
m_currentMisspelledPosition = -1;
}
void SpellCheckMenu::setMisspelled(const QString word, int position)
void SpellCheckMenu::setMisspelled(const QString word, int position,int length)
{
m_currentMisspelled = word;
m_lengthMisspelled=length;
m_currentMisspelledPosition = position;
}
......@@ -146,7 +148,7 @@ void SpellCheckMenu::replaceWord(const QString &suggestion)
if (suggestion.isEmpty() || m_currentMisspelledPosition < 0)
return;
m_spellCheck->replaceWordBySuggestion(suggestion, m_currentMisspelledPosition);
m_spellCheck->replaceWordBySuggestion(suggestion, m_currentMisspelledPosition,m_lengthMisspelled);
m_currentMisspelled.clear();
m_currentMisspelledPosition = -1;
......
/* This file is part of the KDE project
* Copyright (C) 2010 Christoph Goerlich <chgoerlich@gmx.de>
* Copyright (C) 2012 Shreya Pandit <shreya@shreyapandit.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -39,7 +40,7 @@ public:
~SpellCheckMenu();
QPair<QString, KAction*> menuAction();
void setMisspelled(const QString word, int position);
void setMisspelled(const QString word, int position,int length);
void setEnabled(bool b);
void setVisible(bool b);
void setCurrentLanguage(const QString &language);
......@@ -60,6 +61,7 @@ private:
KAction *m_ignoreWordAction;
KAction *m_addToDictionaryAction;
KMenu *m_suggestionsMenu;
int m_lengthMisspelled;
QSignalMapper *m_suggestionsSignalMapper;
int m_currentMisspelledPosition;
QString m_currentMisspelled;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment