>>>>> "Jean-Marc" == Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:

Jean-Marc> An alternative way of doing it would be not to use
Jean-Marc> cursorLeftOneWord at all, but do the move to the left 'by
Jean-Marc> hand'. Would you prefer that?

OK, I just did that and it turns out to be much simpler. Additionally,
the following patch does the following:

- use Paragraph::isWord, like cursorLeftOneWord does; the old code was
  not consistent, since the criterion for finding the beginning of the
  word was not the same than for finding the right part

- change Paragraph::isWord to report true for insets that have the
  isLetter property. This is the case for ligature breaks and
  hyphenation points. Now these characters are not a problem anymore
  for index entries, for example.

I like this patch so much that I am just going to apply it :)

Note that there are still two ways to define what a word is:

- IsLetter lists all the characters that can be part of a word.
  This is used by the spellchecker

- isWord is true except if the character is a known word separator.
  This is used by the word-related cursor functions.

Of course having two ways of defining the same thing is not very
healthy... We'll fix it later, I guess.

JMarc

Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.1928
diff -u -p -r1.1928 ChangeLog
--- src/ChangeLog	27 Jun 2004 13:14:07 -0000	1.1928
+++ src/ChangeLog	29 Jun 2004 15:25:21 -0000
@@ -1,3 +1,11 @@
+2004-06-29  Jean-Marc Lasgouttes  <[EMAIL PROTECTED]>
+
+	* paragraph.C (isWord): return true on insets that report
+	isLetter().
+
+	* text.C (getWord): use Paragraph::isWord to decide what is in a
+	word and what is not; fix bug 1609.
+
 2004-06-27  Jürgen Spitzmüller  <[EMAIL PROTECTED]>
 
 	* tex-strings.C: add "none" to string_paperpackages[], fixes
Index: src/text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.564
diff -u -p -r1.564 text.C
--- src/text.C	17 May 2004 11:28:27 -0000	1.564
+++ src/text.C	29 Jun 2004 15:25:21 -0000
@@ -1842,46 +1842,36 @@ void LyXText::getWord(CursorSlice & from
 	switch (loc) {
 	case lyx::WHOLE_WORD_STRICT:
 		if (from.pos() == 0 || from.pos() == from_par.size()
-		    || from_par.isSeparator(from.pos())
-		    || from_par.isKomma(from.pos())
-		    || from_par.isNewline(from.pos())
-		    || from_par.isSeparator(from.pos() - 1)
-		    || from_par.isKomma(from.pos() - 1)
-		    || from_par.isNewline(from.pos() - 1)) {
+		    || !from_par.isWord(from.pos())
+		    || !from_par.isWord(from.pos() - 1)) {
 			to = from;
 			return;
 		}
 		// no break here, we go to the next
 
 	case lyx::WHOLE_WORD:
-		// Move cursor to the beginning, when not already there.
-		if (from.pos() && !from_par.isSeparator(from.pos() - 1)
-		    && !(from_par.isKomma(from.pos() - 1)
-			 || from_par.isNewline(from.pos() - 1)))
-			cursorLeftOneWord(bv()->cursor());
-		break;
+		// If we are already at the beginning of a word, do nothing
+		if (!from.pos() || !from_par.isWord(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
-		cursorLeftOneWord(bv()->cursor());
+		while (from.pos() && from_par.isWord(from.pos() - 1))
+			--from.pos();
 		break;
 	case lyx::NEXT_WORD:
 		lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
 		       << endl;
 		break;
 	case lyx::PARTIAL_WORD:
+		// no need to move the 'from' cursor
 		break;
 	}
 	to = from;
 	Paragraph & to_par = pars_[to.par()];
-	while (to.pos() < to_par.size()
-	       && !to_par.isSeparator(to.pos())
-	       && !to_par.isKomma(to.pos())
-	       && !to_par.isNewline(to.pos())
-	       && !to_par.isHfill(to.pos())
-	       && !to_par.isInset(to.pos()))
-	{
+	while (to.pos() < to_par.size() && to_par.isWord(to.pos()))
 		++to.pos();
-	}
 }
 
 
Index: src/paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.368
diff -u -p -r1.368 paragraph.C
--- src/paragraph.C	17 May 2004 11:28:26 -0000	1.368
+++ src/paragraph.C	29 Jun 2004 15:25:21 -0000
@@ -1524,7 +1524,9 @@ bool Paragraph::isLetter(pos_type pos) c
 
 bool Paragraph::isWord(pos_type pos) const
 {
-	unsigned char const c = getChar(pos);
+	if (isInset(pos))
+		return getInset(pos)->isLetter();
+	value_type const c = getChar(pos);
 	return !(IsSeparatorChar(c)
 		  || IsKommaChar(c)
 		  || IsInsetChar(c));

Reply via email to