Fix bug #6378: Word completion (in texted) should be language-sensitive.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32581 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2009-12-18 14:48:56 +00:00
parent b3128dc63b
commit 3efb1572a2
5 changed files with 54 additions and 19 deletions

View File

@ -51,6 +51,8 @@ public:
bool internalFontEncoding() const;
///
bool read(Lexer & lex);
// for the use in std::map
friend bool operator<(Language const & p, Language const & q);
private:
///
std::string lang_;
@ -70,6 +72,13 @@ private:
std::string latex_options_;
};
inline bool operator<(Language const & p, Language const & q)
{
return q.lang() > p.lang();
}
class Languages
{
public:

View File

@ -208,9 +208,9 @@ public:
///
TextContainer text_;
typedef std::set<docstring> Words;
typedef set<docstring> Words;
///
Words words_;
map<Language, Words> words_;
///
Layout const * layout_;
};
@ -2401,7 +2401,7 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
bool emph_flag = false;
bool bold_flag = false;
std::string closing_tag;
string closing_tag;
Layout const & style = *d->layout_;
@ -3022,10 +3022,13 @@ bool Paragraph::isSeparator(pos_type pos) const
void Paragraph::deregisterWords()
{
map<Language, Private::Words>::const_iterator itl;
Private::Words::const_iterator it;
WordList & wl = theWordList();
for (it = d->words_.begin(); it != d->words_.end(); ++it)
wl.remove(*it);
for (itl = d->words_.begin(); itl != d->words_.end(); ++itl) {
WordList * wl = theWordList(itl->first);
for (it = (itl->second).begin(); it != (itl->second).end(); ++it)
wl->remove(*it);
}
d->words_.clear();
}
@ -3077,7 +3080,11 @@ void Paragraph::collectWords()
locateWord(from, pos, WHOLE_WORD);
if (pos - from >= 6) {
docstring word = asString(from, pos, AS_STR_NONE);
d->words_.insert(word);
FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
if (cit == d->fontlist_.end())
return;
Language const * lang = cit->font().language();
d->words_[*lang].insert(word);
}
}
}
@ -3085,10 +3092,13 @@ void Paragraph::collectWords()
void Paragraph::registerWords()
{
map<Language, Private::Words>::const_iterator itl;
Private::Words::const_iterator it;
WordList & wl = theWordList();
for (it = d->words_.begin(); it != d->words_.end(); ++it)
wl.insert(*it);
for (itl = d->words_.begin(); itl != d->words_.end(); ++itl) {
WordList * wl = theWordList(itl->first);
for (it = (itl->second).begin(); it != (itl->second).end(); ++it)
wl->insert(*it);
}
}

View File

@ -485,8 +485,8 @@ class TextCompletionList : public CompletionList
{
public:
///
TextCompletionList(Cursor const & cur)
: buffer_(cur.buffer()), pos_(0)
TextCompletionList(Cursor const & cur, WordList const * list)
: buffer_(cur.buffer()), pos_(0), list_(list)
{}
///
virtual ~TextCompletionList() {}
@ -496,12 +496,12 @@ public:
///
virtual size_t size() const
{
return theWordList().size();
return list_->size();
}
///
virtual docstring const & data(size_t idx) const
{
return theWordList().word(idx);
return list_->word(idx);
}
private:
@ -509,6 +509,8 @@ private:
Buffer const * buffer_;
///
size_t pos_;
///
WordList const * list_;
};
@ -1988,7 +1990,8 @@ bool Text::completionSupported(Cursor const & cur) const
CompletionList const * Text::createCompletionList(Cursor const & cur) const
{
return new TextCompletionList(cur);
WordList const * list = theWordList(*cur.getFont().language());
return new TextCompletionList(cur, list);
}

View File

@ -12,6 +12,8 @@
#include "WordList.h"
#include "Language.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstring.h"
@ -19,14 +21,23 @@
#include "support/lassert.h"
#include <map>
using namespace std;
namespace lyx {
///
WordList theGlobalWordList;
map<Language, WordList *> theGlobalWordList;
WordList & theWordList()
WordList * theWordList(Language const & lang)
{
return theGlobalWordList;
map<Language, WordList *>::iterator it = theGlobalWordList.find(lang);
if (it != theGlobalWordList.end())
return it->second;
else
theGlobalWordList[lang] = new WordList();
return theGlobalWordList[lang];
}
///

View File

@ -14,6 +14,8 @@
#include "support/docstring.h"
#include "Language.h"
namespace lyx {
class WordList {
@ -37,7 +39,7 @@ private:
Impl * d;
};
WordList & theWordList();
WordList * theWordList(Language const & lang);
} // namespace lyx