Did I send this one already? Don't see it on the list.

This searches previous, current and next paragraph. I made bruteFind3 do
this, which was also simpler than I thought... and, I think, rather
risk-free. 

This is nice and snappy. (Why would using the cache be better?)

...and what shall we do about 1.4.0?

- Martin

Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.142
diff -u -p -r1.142 cursor.C
--- cursor.C    19 Jan 2006 15:49:20 -0000      1.142
+++ cursor.C    20 Jan 2006 14:54:57 -0000
@@ -162,15 +162,14 @@ namespace {
        /// moves position closest to (x, y) in given box
        bool bruteFind3(LCursor & cur, int x, int y, bool up)
        {
+               // Scans three paragraphs in main document around cursor
                BufferView & bv = cur.bv();
                int ylow  = up ? 0 : y + 1;
                int yhigh = up ? y - 1 : bv.workHeight();
                int xlow = 0;
                int xhigh = bv.workWidth();
 
-// FIXME: bit more work needed to get 'from' and 'to' right.
                pit_type from = cur.bottom().pit();
-               //pit_type to = cur.bottom().pit();
                //lyxerr << "Pit start: " << from << endl;
 
                //lyxerr << "bruteFind3: x: " << x << " y: " << y
@@ -179,9 +178,14 @@ namespace {
                //      << endl;
                InsetBase & inset = bv.buffer()->inset();
                DocIterator it = doc_iterator_begin(inset);
-               it.pit() = from;
-               DocIterator et = doc_iterator_end(inset);
-
+               // Previous paragraph:
+               it.pit() = std::max(from - 1, 0);
+               DocIterator et = it;
+               // Start of paragraph after next:
+               et.forwardPar(); 
+               et.forwardPar(); 
+               et.forwardPar();
+               
                double best_dist = std::numeric_limits<double>::max();
                DocIterator best_cursor = et;
 
@@ -1032,9 +1036,7 @@ bool LCursor::goUpDown(bool up)
                // no such inset found, just take something "above"
                if (!popLeft()) {
                        //lyxerr << "updown: popleft failed (strange case)" << 
endl;
-                       int ylow  = up ? 0 : yo + 1;
-                       int yhigh = up ? yo - 1 : bv().workHeight();
-                       return bruteFind(*this, xo, yo, 0, bv().workWidth(), 
ylow, yhigh);
+                       return bruteFind3(*this, xo, yo, up);
                }
 
                // any improvement so far?

Attachment: pgpBeb4festKz.pgp
Description: PGP signature

Reply via email to