On Fri, Jan 20, 2006 at 04:04:36PM +0100, Jean-Marc Lasgouttes wrote:
> >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> Martin> The slowness is really huge, so yes, that's what I think.
> 
> Martin> I didn't give up though... attached a modification of
> Martin> bruteFind3 that does the three-paragraph trick. There is still
> Martin> a slight delay, but it's much better now. Give it a try. My
> Martin> feeling is that this is as risk-free as the workaround, but
> Martin> not as ugly.
> 
> +             // Start of paragraph after next:
> +             et.forwardPar(); 
> +             et.forwardPar(); 
> +             et.forwardPar();
> 
> This does not work if your paragraphs contain text insets (forwardPar
> goes inside). What you need is something like 
>   et.pit() += 3;
> but some checking is needed for end of document.

Ah yes... thanks. The attached should be OK in this respect.

It's snappy for me... BTW there is something rotten also in cursor
positioning _inside_ math arrays, both regarding correctness and speed.

- 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 20:25:14 -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,13 +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);
 
                double best_dist = std::numeric_limits<double>::max();
                DocIterator best_cursor = et;
 
-               for ( ; it != et; it.forwardPos()) {
+               for ( ; it != et && it.pit() < from + 2; it.forwardPos()) {
                        // avoid invalid nesting when selecting
                        if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE
                            && (!cur.selection() || positionable(it, 
cur.anchor_))) {
@@ -1032,9 +1032,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: pgpyhy6y5R8gz.pgp
Description: PGP signature

Reply via email to