mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 11:16:55 +00:00
get rid of Paragraph::isWord; ignore words with digits in spellchecker
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9268 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
feb701e35e
commit
020972b7f9
@ -1,9 +1,18 @@
|
||||
2004-11-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* paragraph.C (isLetter): remove special spellchecker-related
|
||||
code; return true also for digits
|
||||
(isWord, isKomma): remove
|
||||
|
||||
* text.C (cursorRightOneWord, cursorLeftOneWord, getWord):
|
||||
* lyxfind.C (MatchString()): use isLetter instead of isWord
|
||||
|
||||
2004-11-17 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* pariterator.h (operatir=): comment out un-implemented member
|
||||
function.
|
||||
|
||||
* paragraph.h: resolv ambiguity found by gcc 4.0 with the use of a
|
||||
* paragraph.h: resolve ambiguity found by gcc 4.0 with the use of a
|
||||
static cast.
|
||||
|
||||
2004-11-17 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
@ -1,3 +1,9 @@
|
||||
2004-11-18 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* ControlSpellchecker.C (nextWord): rewrite to skip words
|
||||
containing digits.
|
||||
(isLetter): honor lyxrc.isp_esc_chars
|
||||
|
||||
2004-11-18 Georg Baum <Georg.Baum@post.rwth-aachen.de>
|
||||
|
||||
* ControlTabular.C (initialiseParams): Compute the active cell
|
||||
|
@ -32,6 +32,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "support/textutils.h"
|
||||
#include "support/tostr.h"
|
||||
|
||||
#include "frontends/Alert.h"
|
||||
@ -44,6 +45,7 @@ using std::string;
|
||||
namespace lyx {
|
||||
|
||||
using support::bformat;
|
||||
using support::contains;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
@ -121,7 +123,10 @@ bool isLetter(DocIterator const & cur)
|
||||
return cur.inTexted()
|
||||
&& cur.inset().allowSpellCheck()
|
||||
&& cur.pos() != cur.lastpos()
|
||||
&& cur.paragraph().isLetter(cur.pos())
|
||||
&& (cur.paragraph().isLetter(cur.pos())
|
||||
// We want to pass the ' and escape chars to ispell
|
||||
|| contains(lyxrc.isp_esc_chars + '\'',
|
||||
cur.paragraph().getChar(cur.pos())))
|
||||
&& !isDeletedText(cur.paragraph(), cur.pos());
|
||||
}
|
||||
|
||||
@ -129,25 +134,40 @@ bool isLetter(DocIterator const & cur)
|
||||
WordLangTuple nextWord(DocIterator & cur, ptrdiff_t & progress,
|
||||
BufferParams & bp)
|
||||
{
|
||||
// skip until we have real text (will jump paragraphs)
|
||||
for (; cur.size() && !isLetter(cur); cur.forwardPos());
|
||||
bool inword = false;
|
||||
bool ignoreword = false;
|
||||
string word, lang_code;
|
||||
|
||||
while(cur.size()) {
|
||||
if (isLetter(cur)) {
|
||||
if (!inword) {
|
||||
inword = true;
|
||||
ignoreword = false;
|
||||
word.clear();
|
||||
lang_code = cur.paragraph().getFontSettings(bp, cur.pos()).language()->code();
|
||||
}
|
||||
// Insets like optional hyphens and ligature
|
||||
// break are part of a word.
|
||||
if (!cur.paragraph().isInset(cur.pos())) {
|
||||
Paragraph::value_type const c =
|
||||
cur.paragraph().getChar(cur.pos());
|
||||
word += c;
|
||||
if (IsDigit(c))
|
||||
ignoreword = true;
|
||||
}
|
||||
} else { // !isLetter(cur)
|
||||
if (inword)
|
||||
if (!ignoreword)
|
||||
return WordLangTuple(word, lang_code);
|
||||
else
|
||||
inword = false;
|
||||
}
|
||||
|
||||
cur.forwardPos();
|
||||
++progress;
|
||||
|
||||
// hit end
|
||||
if (cur.empty())
|
||||
return WordLangTuple(string(), string());
|
||||
|
||||
string lang_code = cur.paragraph().
|
||||
getFontSettings(bp, cur.pos()).language()->code();
|
||||
string str;
|
||||
// and find the end of the word (insets like optional hyphens
|
||||
// and ligature break are part of a word)
|
||||
for (; cur && isLetter(cur); cur.forwardPos(), ++progress) {
|
||||
if (!cur.paragraph().isInset(cur.pos()))
|
||||
str += cur.paragraph().getChar(cur.pos());
|
||||
}
|
||||
|
||||
return WordLangTuple(str, lang_code);
|
||||
return WordLangTuple(string(), string());
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
@ -85,10 +85,10 @@ public:
|
||||
|
||||
// if necessary, check whether string matches word
|
||||
if (mw) {
|
||||
if (pos > 0 && par.isWord(pos - 1))
|
||||
if (pos > 0 && par.isLetter(pos - 1))
|
||||
return false;
|
||||
if (pos + lyx::pos_type(size) < parsize
|
||||
&& par.isWord(pos + size));
|
||||
&& par.isLetter(pos + size));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,6 @@
|
||||
|
||||
using lyx::pos_type;
|
||||
|
||||
using lyx::support::contains;
|
||||
using lyx::support::subst;
|
||||
|
||||
using std::distance;
|
||||
@ -1510,34 +1509,15 @@ bool Paragraph::isLineSeparator(pos_type pos) const
|
||||
}
|
||||
|
||||
|
||||
bool Paragraph::isKomma(pos_type pos) const
|
||||
{
|
||||
return IsKommaChar(getChar(pos));
|
||||
}
|
||||
|
||||
|
||||
/// Used by the spellchecker
|
||||
bool Paragraph::isLetter(pos_type pos) const
|
||||
{
|
||||
value_type const c = getChar(pos);
|
||||
if (IsLetterChar(c))
|
||||
return true;
|
||||
if (isInset(pos))
|
||||
return getInset(pos)->isLetter();
|
||||
// We want to pass the ' and escape chars to ispell
|
||||
string const extra = lyxrc.isp_esc_chars + '\'';
|
||||
return contains(extra, c);
|
||||
}
|
||||
|
||||
|
||||
bool Paragraph::isWord(pos_type pos) const
|
||||
{
|
||||
if (isInset(pos))
|
||||
return getInset(pos)->isLetter();
|
||||
value_type const c = getChar(pos);
|
||||
return !(IsSeparatorChar(c)
|
||||
|| IsKommaChar(c)
|
||||
|| IsInsetChar(c));
|
||||
else {
|
||||
value_type const c = getChar(pos);
|
||||
return IsLetterChar(c) || IsDigit(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -335,12 +335,9 @@ public:
|
||||
bool isSeparator(lyx::pos_type pos) const;
|
||||
///
|
||||
bool isLineSeparator(lyx::pos_type pos) const;
|
||||
///
|
||||
bool isKomma(lyx::pos_type pos) const;
|
||||
/// Used by the spellchecker
|
||||
/// True if the character/inset at this point can be part of a word
|
||||
// Note that digits in particular are considered as letters
|
||||
bool isLetter(lyx::pos_type pos) const;
|
||||
///
|
||||
bool isWord(lyx::pos_type pos) const;
|
||||
|
||||
/// returns -1 if inset not found
|
||||
int getPositionOfInset(InsetBase const * inset) const;
|
||||
|
@ -1,3 +1,7 @@
|
||||
2004-11-16 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
|
||||
|
||||
* textutils.h (isKommaChar): remove
|
||||
|
||||
2004-11-16 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* forkedcontr.C (find_pid): simplify and also make pass concept
|
||||
@ -13,7 +17,7 @@
|
||||
|
||||
2004-11-07 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
* Make it clearer where include files are comming from.
|
||||
* Make it clearer where include files are coming from.
|
||||
|
||||
2004-11-06 Lars Gullik Bjonnes <larsbj@gullik.net>
|
||||
|
||||
|
@ -31,36 +31,6 @@ bool IsLineSeparatorChar(char c)
|
||||
}
|
||||
|
||||
|
||||
/// return true if the char is "punctuation"
|
||||
inline
|
||||
bool IsKommaChar(char c)
|
||||
{
|
||||
return c == ','
|
||||
|| c == '('
|
||||
|| c == ')'
|
||||
|| c == '['
|
||||
|| c == ']'
|
||||
|| c == '{'
|
||||
|| c == '}'
|
||||
|| c == ';'
|
||||
|| c == '.'
|
||||
|| c == ':'
|
||||
|| c == '-'
|
||||
|| c == '?'
|
||||
|| c == '!'
|
||||
|| c == '&'
|
||||
|| c == '@'
|
||||
|| c == '+'
|
||||
|| c == '-'
|
||||
|| c == '~'
|
||||
|| c == '#'
|
||||
|| c == '%'
|
||||
|| c == '^'
|
||||
|| c == '/'
|
||||
|| c == '\\';
|
||||
}
|
||||
|
||||
|
||||
/// return true if a char is alphabetical (including accented chars)
|
||||
inline
|
||||
bool IsLetterChar(unsigned char c)
|
||||
|
18
src/text.C
18
src/text.C
@ -1355,10 +1355,10 @@ void LyXText::cursorRightOneWord(LCursor & cur)
|
||||
} else {
|
||||
// Skip through initial nonword stuff.
|
||||
// Treat floats and insets as words.
|
||||
while (cur.pos() != cur.lastpos() && !cur.paragraph().isWord(cur.pos()))
|
||||
while (cur.pos() != cur.lastpos() && !cur.paragraph().isLetter(cur.pos()))
|
||||
++cur.pos();
|
||||
// Advance through word.
|
||||
while (cur.pos() != cur.lastpos() && cur.paragraph().isWord(cur.pos()))
|
||||
while (cur.pos() != cur.lastpos() && cur.paragraph().isLetter(cur.pos()))
|
||||
++cur.pos();
|
||||
}
|
||||
setCursor(cur, cur.par(), cur.pos());
|
||||
@ -1374,10 +1374,10 @@ void LyXText::cursorLeftOneWord(LCursor & cur)
|
||||
} else {
|
||||
// Skip through initial nonword stuff.
|
||||
// Treat floats and insets as words.
|
||||
while (cur.pos() != 0 && !cur.paragraph().isWord(cur.pos() - 1))
|
||||
while (cur.pos() != 0 && !cur.paragraph().isLetter(cur.pos() - 1))
|
||||
--cur.pos();
|
||||
// Advance through word.
|
||||
while (cur.pos() != 0 && cur.paragraph().isWord(cur.pos() - 1))
|
||||
while (cur.pos() != 0 && cur.paragraph().isLetter(cur.pos() - 1))
|
||||
--cur.pos();
|
||||
}
|
||||
setCursor(cur, cur.par(), cur.pos());
|
||||
@ -1797,8 +1797,8 @@ void LyXText::getWord(CursorSlice & from, CursorSlice & to,
|
||||
switch (loc) {
|
||||
case lyx::WHOLE_WORD_STRICT:
|
||||
if (from.pos() == 0 || from.pos() == from_par.size()
|
||||
|| !from_par.isWord(from.pos())
|
||||
|| !from_par.isWord(from.pos() - 1)) {
|
||||
|| !from_par.isLetter(from.pos())
|
||||
|| !from_par.isLetter(from.pos() - 1)) {
|
||||
to = from;
|
||||
return;
|
||||
}
|
||||
@ -1806,13 +1806,13 @@ void LyXText::getWord(CursorSlice & from, CursorSlice & to,
|
||||
|
||||
case lyx::WHOLE_WORD:
|
||||
// If we are already at the beginning of a word, do nothing
|
||||
if (!from.pos() || !from_par.isWord(from.pos() - 1))
|
||||
if (!from.pos() || !from_par.isLetter(from.pos() - 1))
|
||||
break;
|
||||
// no break here, we go to the next
|
||||
|
||||
case lyx::PREVIOUS_WORD:
|
||||
// always move the cursor to the beginning of previous word
|
||||
while (from.pos() && from_par.isWord(from.pos() - 1))
|
||||
while (from.pos() && from_par.isLetter(from.pos() - 1))
|
||||
--from.pos();
|
||||
break;
|
||||
case lyx::NEXT_WORD:
|
||||
@ -1825,7 +1825,7 @@ void LyXText::getWord(CursorSlice & from, CursorSlice & to,
|
||||
}
|
||||
to = from;
|
||||
Paragraph & to_par = pars_[to.par()];
|
||||
while (to.pos() < to_par.size() && to_par.isWord(to.pos()))
|
||||
while (to.pos() < to_par.size() && to_par.isLetter(to.pos()))
|
||||
++to.pos();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user