Check the right substrings in the spellchecker dialog. Closes #1560.

This commit is contained in:
Thomas Goyne 2012-12-12 18:07:53 -08:00
parent 72ae116196
commit 4e72fff1d9

View file

@ -21,15 +21,6 @@
#include "config.h"
#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/intl.h>
#include <wx/listbox.h>
#include <wx/msgdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include "dialog_spellchecker.h"
#include "ass_dialogue.h"
@ -49,6 +40,15 @@
#include <libaegisub/exception.h>
#include <libaegisub/spellchecker.h>
#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/intl.h>
#include <wx/listbox.h>
#include <wx/msgdlg.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
DialogSpellChecker::DialogSpellChecker(agi::Context *context)
: wxDialog(context->parent, -1, _("Spell Checker"))
, context(context)
@ -245,14 +245,18 @@ bool DialogSpellChecker::CheckLine(AssDialogue *active_line, int start_pos, int
word_start = 0;
for (auto const& tok : tokens) {
word_start += tok.length;
if (tok.type != agi::ass::DialogueTokenType::WORD) continue;
if (word_start < start_pos) continue;
if (tok.type != agi::ass::DialogueTokenType::WORD || word_start < start_pos) {
word_start += tok.length;
continue;
}
word_len = tok.length;
std::string word = text.substr(word_start, word_len);
if (auto_ignore.count(word) || spellchecker->CheckWord(word)) continue;
if (auto_ignore.count(word) || spellchecker->CheckWord(word)) {
word_start += tok.length;
continue;
}
auto auto_rep = auto_replace.find(word);
if (auto_rep == auto_replace.end()) {
@ -272,7 +276,7 @@ bool DialogSpellChecker::CheckLine(AssDialogue *active_line, int start_pos, int
text.replace(word_start, word_len, auto_rep->second);
active_line->Text = from_wx(text);
*commit_id = context->ass->Commit(_("spell check replace"), AssFile::COMMIT_DIAG_TEXT, *commit_id);
word_start += auto_rep->second.size() - auto_rep->first.size();
word_start += auto_rep->second.size();
}
return false;
}