On Friday 15 August 2003 17:19, André wrote: > > > Ok. What about paragraph count from beginning plus position within? > > > > Fine... and you can even drop the position I guess. > > > > I wonder if this anchor_par_ shouldn't be stored on the bufferview > > instead of the lyxtext. > > Good idea actually. The insets don't use 'their' anchor anyway. > > > Another thing: the anchor_row_ was also used to speed up getRowNearY and > > friends (yes, *after* real profiling) so I guess we should pay attention > > to preformance if we do the change. > > This code is currently broken. I don't understand the '- 1 row magic' > needed to make it work -- which in turn mean that we never reach the > last row of a par with 'setCursorFromCoordinate' - which is bad. > > I wouldn't mind if you had a look ;-)
The -1 row is right because it seems that the convention for getRowNearY(y) is to return 'the last row with y coordinate less or equal than y' In this case, the absolute last row would be reached if y is big enough, i.e. something like this should do: Index: text.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v retrieving revision 1.421 diff -u -p -u -r1.421 text.C --- text.C 15 Aug 2003 15:20:50 -0000 1.421 +++ text.C 15 Aug 2003 21:24:22 -0000 @@ -2150,7 +2150,7 @@ RowList::iterator LyXText::cursorIRow() RowList::iterator LyXText::getRowNearY(int & y, - ParagraphList::iterator & pit) const + ParagraphList::iterator & pit) const { ParagraphList::iterator const end = ownerParagraphs().end(); //lyxerr << "getRowNearY: y " << y << endl; @@ -2170,15 +2170,16 @@ RowList::iterator LyXText::getRowNearY(i } } -#if 1 +#if 0 pit = ownerParagraphs().begin(); y = 0; lyxerr << "row not found near " << y << " pit: " << &*pit << endl; return firstRow(); #else + RowList::iterator rit = lastRow(); + y = rit->y(); pit = boost::prior(ownerParagraphs().end()); - lyxerr << "row not found near " << y << " pit: " << &*pit << endl; - return lastRow(); + return rit; #endif } Of course the whole thing could be written in a more natural way with nextRow (slightly slower maybe): RowList::iterator LyXText::getRowNearY(int & y, ParagraphList::iterator & pit) const { //lyxerr << "getRowNearY: y " << y << endl; pit = ownerParagraphs().begin(); RowList::iterator rit = firstRow(); RowList::iterator rend = endRow(); for (; rit != rend; nextRow(pit, rit)) if (rit->y() > y) break; previousRow(pit, rit); y = rit->y(); return rit; } (note that for this to work correctly, the following fix is needed for nextRow): @@ -2208,25 +2209,22 @@ RowList::iterator LyXText::endRow() cons void LyXText::nextRow(ParagraphList::iterator & pit, RowList::iterator & rit) const { if (boost::next(rit) != pit->rows.end()) { rit = boost::next(rit); } else { ++pit; - if (pit == ownerParagraphs().end()) + if (pit == ownerParagraphs().end()) { rit = boost::next(rit); + --pit; - else + } else rit = pit->rows.begin(); } } Regards, Alfredo