mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-10 20:04:46 +00:00
Paragraph::collectWords() and MenuDefinition::expandSpellingSuggestions(): reuse Paragraph::spellCheck().
Paragraph::collectWords() now also collects spellchecker suggested words for inline word completion. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30240 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ae9bcc7760
commit
5d40a42f60
@ -3027,40 +3027,24 @@ void Paragraph::locateWord(pos_type & from, pos_type & to,
|
||||
|
||||
void Paragraph::collectWords()
|
||||
{
|
||||
SpellChecker * speller = theSpellChecker();
|
||||
|
||||
//lyxerr << "Words: ";
|
||||
pos_type n = size();
|
||||
WordLangTuple wl;
|
||||
docstring_list suggestions;
|
||||
for (pos_type pos = 0; pos < n; ++pos) {
|
||||
if (isWordSeparator(pos))
|
||||
continue;
|
||||
pos_type from = pos;
|
||||
locateWord(from, pos, WHOLE_WORD);
|
||||
if (!lyxrc.spellcheck_continuously && pos - from < 6)
|
||||
continue;
|
||||
|
||||
docstring word = asString(from, pos, false);
|
||||
if (pos - from >= 6)
|
||||
if (pos - from >= 6) {
|
||||
docstring word = asString(from, pos, AS_STR_NONE);
|
||||
d->words_.insert(word);
|
||||
|
||||
if (!lyxrc.spellcheck_continuously || !speller)
|
||||
continue;
|
||||
|
||||
string const lang_code = lyxrc.spellchecker_alt_lang.empty()
|
||||
? getFontSettings(d->inset_owner_->buffer().params(), from).language()->code()
|
||||
: lyxrc.spellchecker_alt_lang;
|
||||
WordLangTuple wl(word, lang_code);
|
||||
SpellChecker::Result res = speller->check(wl);
|
||||
// ... just ignore any error that the spellchecker reports.
|
||||
if (!speller->error().empty())
|
||||
continue;
|
||||
bool const misspelled = res != SpellChecker::OK
|
||||
&& res != SpellChecker::IGNORED_WORD;
|
||||
d->fontlist_.setMisspelled(from, pos, misspelled);
|
||||
|
||||
//lyxerr << word << " ";
|
||||
}
|
||||
if (lyxrc.spellcheck_continuously
|
||||
&& spellCheck(from, pos, wl, suggestions)) {
|
||||
for (size_t i = 0; i != suggestions.size(); ++i)
|
||||
d->words_.insert(suggestions[i]);
|
||||
}
|
||||
}
|
||||
//lyxerr << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,10 +46,10 @@
|
||||
#include "Paragraph.h"
|
||||
#include "ParIterator.h"
|
||||
#include "Session.h"
|
||||
#include "SpellChecker.h"
|
||||
#include "TextClass.h"
|
||||
#include "TocBackend.h"
|
||||
#include "Toolbars.h"
|
||||
#include "WordLangTuple.h"
|
||||
|
||||
#include "insets/Inset.h"
|
||||
#include "insets/InsetCitation.h"
|
||||
@ -718,26 +718,26 @@ void MenuDefinition::expandSpellingSuggestions(BufferView const * bv)
|
||||
{
|
||||
if (!bv)
|
||||
return;
|
||||
WordLangTuple wl;
|
||||
docstring_list suggestions;
|
||||
pos_type from = bv->cursor().pos();
|
||||
pos_type to = from;
|
||||
Paragraph const & par = bv->cursor().paragraph();
|
||||
if (!par.isMisspelled(bv->cursor().pos()))
|
||||
if (!par.spellCheck(from, to, wl, suggestions))
|
||||
return;
|
||||
LYXERR0("Misspelled Word!");
|
||||
|
||||
SpellChecker * speller = theSpellChecker();
|
||||
docstring word;
|
||||
int i = 0;
|
||||
LYXERR(Debug::GUI, "Misspelled Word! Suggested Words = ");
|
||||
size_t i = 0;
|
||||
MenuItem item(MenuItem::Submenu, qt_("more spelling suggestions"));
|
||||
item.setSubmenu(MenuDefinition(qt_("more spelling suggestions")));
|
||||
while (!(word = speller->nextMiss()).empty()) {
|
||||
LYXERR0("Misspelled Word = " << word);
|
||||
MenuItem w(MenuItem::Command, toqstr(word),
|
||||
FuncRequest(LFUN_WORD_REPLACE, word));
|
||||
if (i < 10) {
|
||||
for (; i != suggestions.size(); ++i) {
|
||||
docstring const & suggestion = suggestions[i];
|
||||
LYXERR(Debug::GUI, suggestion);
|
||||
MenuItem w(MenuItem::Command, toqstr(suggestion),
|
||||
FuncRequest(LFUN_WORD_REPLACE, suggestion));
|
||||
if (i < 10)
|
||||
add(w);
|
||||
} else {
|
||||
else
|
||||
item.submenu().add(w);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (i >= 10)
|
||||
add(item);
|
||||
|
Loading…
Reference in New Issue
Block a user