See: http://bugzilla.lyx.org/show_bug.cgi?id=1609
This patch fixes LyXText::getWord to operate on full LCursor instances instead of simple CursorSlices. This fixes word selection, which was the problem in bug 1609. I still can't select words by double clicking, but I guess this is a different problem. I am not sure I understand how cursors work in the new world, so I would be grateful if Alfredo or Andre' could have a look at it. All I can say is that it seems to work. Most of it is straightforward changes like 'from' => 'from.top()'. JMarc
Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.1927 diff -u -p -r1.1927 ChangeLog --- src/ChangeLog 23 Jun 2004 14:04:07 -0000 1.1927 +++ src/ChangeLog 24 Jun 2004 15:06:05 -0000 @@ -1,3 +1,10 @@ +2004-06-24 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> + + * text.C (getWord): change to take two LCursor arguments instead of + CursorSlice. This fixes bug 1609. + (changeCase): + (selectWord): adapt to change above + 2004-06-10 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> * lyxfunc.C (getStatus): if lyx_gui::getStatus disables the Index: src/lyxtext.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v retrieving revision 1.309 diff -u -p -r1.309 lyxtext.h --- src/lyxtext.h 21 Apr 2004 19:51:17 -0000 1.309 +++ src/lyxtext.h 24 Jun 2004 15:06:05 -0000 @@ -156,7 +156,7 @@ public: * @param from return here the start of the word * @param to return here the end of the word */ - void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const); + void getWord(LCursor & from, LCursor & to, lyx::word_location const); /// just selects the word the cursor is in void selectWord(LCursor & cur, lyx::word_location loc); 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 24 Jun 2004 15:06:05 -0000 @@ -1413,15 +1413,15 @@ void LyXText::cursorLeftOneWord(LCursor void LyXText::selectWord(LCursor & cur, word_location loc) { BOOST_ASSERT(this == cur.text()); - CursorSlice from = cur.top(); - CursorSlice to = cur.top(); + LCursor from = cur; + LCursor to = cur; getWord(from, to, loc); - if (cur.top() != from) - setCursor(cur, from.par(), from.pos()); - if (to == from) + if (cur.top() != from.top()) + setCursor(cur, from.top().par(), from.top().pos()); + if (to.top() == from.top()) return; cur.resetAnchor(); - setCursor(cur, to.par(), to.pos()); + setCursor(cur, to.top().par(), to.top().pos()); cur.setSelection(); } @@ -1538,24 +1538,23 @@ void LyXText::deleteLineForward(LCursor void LyXText::changeCase(LCursor & cur, LyXText::TextCase action) { BOOST_ASSERT(this == cur.text()); - CursorSlice from; - CursorSlice to; + LCursor from(cur); + LCursor to(cur); if (cur.selection()) { - from = cur.selBegin(); - to = cur.selEnd(); + from.top() = cur.selBegin(); + to.top() = cur.selEnd(); } else { - from = cur.top(); getWord(from, to, lyx::PARTIAL_WORD); - setCursor(cur, to.par(), to.pos() + 1); + setCursor(cur, to.top().par(), to.top().pos() + 1); } recordUndoSelection(cur); - pos_type pos = from.pos(); - int par = from.par(); + pos_type pos = from.top().pos(); + int par = from.top().par(); - while (par != int(pars_.size()) && (pos != to.pos() || par != to.par())) { + while (par != int(pars_.size()) && (pos != to.top().pos() || par != to.top().par())) { par_type pit = par; if (pos == pars_[pit].size()) { ++par; @@ -1835,19 +1834,19 @@ bool LyXText::isFirstRow(par_type pit, R } -void LyXText::getWord(CursorSlice & from, CursorSlice & to, - word_location const loc) +void LyXText::getWord(LCursor & from, LCursor & to, word_location const loc) { - Paragraph & from_par = pars_[from.par()]; + Paragraph const & from_par = pars_[from.top().par()]; + par_type const from_pos = from.top().pos(); 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)) { + 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)) { to = from; return; } @@ -1855,14 +1854,14 @@ void LyXText::getWord(CursorSlice & from 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()); + if (from_pos && !from_par.isSeparator(from_pos - 1) + && !(from_par.isKomma(from_pos - 1) + || from_par.isNewline(from_pos - 1))) + cursorLeftOneWord(from); break; case lyx::PREVIOUS_WORD: // always move the cursor to the beginning of previous word - cursorLeftOneWord(bv()->cursor()); + cursorLeftOneWord(from); break; case lyx::NEXT_WORD: lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet" @@ -1872,15 +1871,15 @@ void LyXText::getWord(CursorSlice & from 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())) + Paragraph const & to_par = pars_[to.top().par()]; + while (to.top().pos() < to_par.size() + && !to_par.isSeparator(to.top().pos()) + && !to_par.isKomma(to.top().pos()) + && !to_par.isNewline(to.top().pos()) + && !to_par.isHfill(to.top().pos()) + && !to_par.isInset(to.top().pos())) { - ++to.pos(); + ++to.top().pos(); } }