* Paragraph.cpp (isChar): new method; returns true when pointer is on
a character that is not a letter. Note that a footnote inset, for
example is neither a letter nor a character.
* Text.cpp (cursorForwardOneWord, cursorBackwardOneWord): rewrite by
using 3 character categories: letters, characters and others.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25373
a592a061-630c-0410-9148-
cb99ea01b6c8
+bool Paragraph::isChar(pos_type pos) const
+{
+ if (Inset const * inset = getInset(pos))
+ return inset->isChar();
+ char_type const c = d->text_[pos];
+ return !isLetterChar(c) && !isDigit(c);
+}
+
+
Language const *
Paragraph::getParLanguage(BufferParams const & bparams) const
{
Language const *
Paragraph::getParLanguage(BufferParams const & bparams) const
{
/// 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(pos_type pos) const;
/// 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(pos_type pos) const;
+ /// True if the element at this point is a character that is not a letter.
+ bool isChar(pos_type pos) const;
/// returns true if at least one line break or line separator has been deleted
/// at the beginning of the paragraph (either physically or logically)
/// returns true if at least one line break or line separator has been deleted
/// at the beginning of the paragraph (either physically or logically)
{
LASSERT(this == cur.text(), /**/);
{
LASSERT(this == cur.text(), /**/);
+ pos_type const lastpos = cur.lastpos();
+ pit_type pit = cur.pit();
+ pos_type pos = cur.pos();
+ Paragraph const & par = cur.paragraph();
- if (old.pos() == old.lastpos() && old.pit() != old.lastpit()) {
- ++old.pit();
- old.pos() = 0;
- } else {
- // Advance through word.
- while (old.pos() != old.lastpos() && old.paragraph().isLetter(old.pos()))
- ++old.pos();
- // Skip through trailing nonword stuff.
- while (old.pos() != old.lastpos() && !old.paragraph().isLetter(old.pos()))
- ++old.pos();
+ // Skip over either a non-char inset or a full word
+ if (pos != lastpos && !par.isLetter(pos) && !par.isChar(pos))
+ ++pos;
+ else while (pos != lastpos && par.isLetter(pos))
+ ++pos;
+
+ // Skip through trailing punctuation and spaces.
+ while (pos != lastpos && par.isChar(pos))
+ ++pos;
+
+ if (pos == lastpos && pit != cur.lastpit()) {
+ ++pit;
+ pos = 0;
- return setCursor(cur, old.pit(), old.pos());
+
+ return setCursor(cur, pit, pos);
{
LASSERT(this == cur.text(), /**/);
{
LASSERT(this == cur.text(), /**/);
+ pit_type pit = cur.pit();
+ pos_type pos = cur.pos();
+ Paragraph & par = cur.paragraph();
- if (old.pos() == 0 && old.pit() != 0) {
- --old.pit();
- old.pos() = old.lastpos();
- } else {
- // Skip through initial nonword stuff.
- while (old.pos() != 0 && !old.paragraph().isLetter(old.pos() - 1))
- --old.pos();
- // Advance through word.
- while (old.pos() != 0 && old.paragraph().isLetter(old.pos() - 1))
- --old.pos();
+ // Skip through puctuation and spaces.
+ while (pos != 0 && par.isChar(pos - 1))
+ --pos;
+
+ // Skip over either a non-char inset or a full word
+ if (pos != 0 && !par.isLetter(pos) && !par.isChar(pos - 1))
+ --pos;
+ else while (pos != 0 && par.isLetter(pos - 1))
+ --pos;
+
+ if (pos == 0 && pit != 0) {
+ --pit;
+ pos = getPar(cur.pit() - 1).size();
- return setCursor(cur, old.pit(), old.pos());
+
+ return setCursor(cur, pit, pos);