On Thu, Sep 22, 2005 at 09:21:31AM -0400, Bennett Helm wrote:
> On Sep 22, 2005, at 4:08 AM, Martin Vermeer wrote:
> 
> >Here is a better patch, taking care of rowpainter too. metrics is  
> >still
> >called twice, but now (generally) only for the current paragraph, not
> >the whole screen. Ought to be faster.
> >
> >I saw no side effects.
> 
> I tried it, and it generally feels quite a bit faster, though there  
> still is considerable lag.
> 
> I did notice a side effect: typing in one paragraph causes text in  
> the paragraph after the next paragraph to be poorly displayed. At  
> first, it looks as though all text in that later paragraph is being  
> displayed one pixel over on top of the previous text (giving the  
> impression of boldface). As I continue typing, text in that paragraph  
> keeps getting displayed progressively further to the right (so that  
> it gradually looks bolder and bolder). Then, when my typing causes a  
> new line to be displayed, the text in that later paragraph is redrawn  
> without erasing the previous text, resulting in the screen shot I've  
> attached.
> 
> The text in that paragraph gets redrawn with a mouse click. But  
> there's a further problem: although clicking above the badly drawn  
> paragraph places the cursor in the right place, clicking below it  
> places the cursor in the last line of the badly drawn paragraph.
> 
> Bennett

Give the attached a try.

I think it is quite a bit faster, and fixes your noticed side effect. 

There may be other side effects; this patch touches so many things, it
scares me a bit. But the speedup is so substantial that perhaps we
should just take the jump, and clean up afterwards. And I have a good
feeling that now SinglePar works as it was intended to.

- Martin

Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.595
diff -u -p -r1.595 BufferView_pimpl.C
--- BufferView_pimpl.C  15 Sep 2005 13:55:45 -0000      1.595
+++ BufferView_pimpl.C  22 Sep 2005 21:47:03 -0000
@@ -666,12 +666,14 @@ void BufferView::Pimpl::update(Update::f
                theCoords.startUpdating();
 
                // First drawing step
-               ViewMetricsInfo vi = metrics();
+               ViewMetricsInfo vi = metrics(flags & Update::SinglePar);
                bool forceupdate(flags & Update::Force);
 
-               if ((flags & Update::FitCursor) && fitCursor()) {
-                       forceupdate = true;
-                       vi = metrics(flags & Update::SinglePar);
+               if (flags & Update::FitCursor) {
+                       if (fitCursor()) {
+                               forceupdate = true;
+                               vi = metrics();
+                       }
                }
                if (forceupdate) {
                        // Second drawing step
@@ -1327,23 +1329,18 @@ ViewMetricsInfo BufferView::Pimpl::metri
        int pit2 = pit;
        size_t const npit = text->paragraphs().size();
 
-       lyxerr[Debug::DEBUG]
-                << BOOST_CURRENT_FUNCTION
-                << " npit: " << npit
-                << " pit1: " << pit1
-                << " pit2: " << pit2
-                << endl;
-
        // Rebreak anchor par
-       text->redoParagraph(pit);
-       int y0 = text->getPar(pit1).ascent() - offset_ref_;
+       if (!singlepar || pit == cursor_.pit()) // only rebreak cursor para
+               text->redoParagraph(pit);
+       int y0 = text->getPar(pit).ascent() - offset_ref_;
 
        // Redo paragraphs above cursor if necessary
        int y1 = y0;
-       while (!singlepar && y1 > 0 && pit1 > 0) {
+       while (y1 > 0 && pit1 > 0) {
                y1 -= text->getPar(pit1).ascent();
                --pit1;
-               text->redoParagraph(pit1);
+               if (!singlepar || pit1 == cursor_.pit())
+                       text->redoParagraph(pit1);
                y1 -= text->getPar(pit1).descent();
        }
 
@@ -1364,10 +1361,11 @@ ViewMetricsInfo BufferView::Pimpl::metri
 
        // Redo paragraphs below cursor if necessary
        int y2 = y0;
-       while (!singlepar && y2 < bv.workHeight() && pit2 < int(npit) - 1) {
+       while (y2 < bv.workHeight() && pit2 < int(npit) - 1) {
                y2 += text->getPar(pit2).descent();
                ++pit2;
-               text->redoParagraph(pit2);
+               if (!singlepar || pit2 == cursor_.pit())
+                       text->redoParagraph(pit2);
                y2 += text->getPar(pit2).ascent();
        }
 
@@ -1379,13 +1377,27 @@ ViewMetricsInfo BufferView::Pimpl::metri
        for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
                y += text->getPar(pit).ascent();
                theCoords.parPos()[text][pit] = Point(0, y);
+               if (singlepar && pit == cursor_.pit()) {
+                       // collect cursor paragraph y's
+                       y1 = y - text->getPar(pit).ascent();
+                       y2 = y + text->getPar(pit).descent();
+               }
                y += text->getPar(pit).descent();
        }
 
+       if (singlepar) { // collect cursor paragraph iter bounds
+               pit1 = cursor_.pit();
+               pit2 = cursor_.pit();
+       }
+       
        lyxerr[Debug::DEBUG]
                 << BOOST_CURRENT_FUNCTION
                 << " y1: " << y1
                 << " y2: " << y2
+                << " pit1: " << pit1
+                << " pit2: " << pit2
+                << " npit: " << npit
+                << " singlepar: " << singlepar
                 << endl;
 
        return ViewMetricsInfo(pit1, pit2, y1, y2, singlepar);
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.668
diff -u -p -r1.668 lyxfunc.C
--- lyxfunc.C   19 Sep 2005 09:55:49 -0000      1.668
+++ lyxfunc.C   22 Sep 2005 21:47:04 -0000
@@ -1556,8 +1556,6 @@ void LyXFunc::dispatch(FuncRequest const
                        // in (at least partially) visible top-level paragraphs.
                        if (update)
                                view()->update(Update::FitCursor | 
Update::Force);
-                       else
-                               view()->update(Update::FitCursor);
 
                        // if we executed a mutating lfun, mark the buffer as 
dirty
                        // FIXME: Why not use flag.enabled() but call getStatus 
again?
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.157
diff -u -p -r1.157 rowpainter.C
--- rowpainter.C        19 Sep 2005 11:18:20 -0000      1.157
+++ rowpainter.C        22 Sep 2005 21:47:04 -0000
@@ -769,30 +769,30 @@ void paintText(BufferView const & bv, Vi
                yy += text->getPar(pit).descent();
        }
 
-
-       // paint one paragraph above and one below
+       // Cache one paragraph above and one below
        // Note MV: this cannot be suppressed even for singlepar.
        // Try viewing the User Guide Mobius figure
+
        if (vi.p1 > 0) {
                text->redoParagraph(vi.p1 - 1);
-               paintPar(pi, *bv.text(), vi.p1 - 1, 0,
-                        vi.y1 -  text->getPar(vi.p1 - 1).descent());
+               theCoords.parPos()[bv.text()][vi.p1 - 1] = 
+                       Point(0, vi.y1 - text->getPar(vi.p1 - 1).descent());
        }
 
        if (vi.p2 < lyx::pit_type(text->paragraphs().size()) - 1) {
                text->redoParagraph(vi.p2 + 1);
-               paintPar(pi, *bv.text(), vi.p2 + 1, 0,
-                        vi.y2 + text->getPar(vi.p2 + 1).ascent());
+               theCoords.parPos()[bv.text()][vi.p2 + 1] = 
+                       Point(0, vi.y2 + text->getPar(vi.p2 + 1).ascent());
        }
 
        // and grey out above (should not happen later)
 //     lyxerr << "par ascent: " << text->getPar(vi.p1).ascent() << endl;
-       if (vi.y1 > 0)
+       if (vi.y1 > 0 && !vi.singlepar)
                pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, 
LColor::bottomarea);
 
        // and possibly grey out below
 //     lyxerr << "par descent: " << text->getPar(vi.p1).ascent() << endl;
-       if (vi.y2 < bv.workHeight())
+       if (vi.y2 < bv.workHeight() && !vi.singlepar)
                pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - 
vi.y2, LColor::bottomarea);
 }
 
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.307
diff -u -p -r1.307 text3.C
--- text3.C     16 Sep 2005 10:06:09 -0000      1.307
+++ text3.C     22 Sep 2005 21:47:07 -0000
@@ -1117,6 +1117,9 @@ void LyXText::dispatch(LCursor & cur, Fu
                current_font.setLanguage(lang);
                real_current_font.setLanguage(lang);
 
+               // Remember the old paragraph metric
+               Dimension olddim = cur.paragraph().dim();
+
                string::const_iterator cit = cmd.argument.begin();
                string::const_iterator end = cmd.argument.end();
                for (; cit != end; ++cit)
@@ -1125,11 +1128,14 @@ void LyXText::dispatch(LCursor & cur, Fu
 
                cur.resetAnchor();
                moveCursor(cur, false);
-
-               needsUpdate = redoParagraph(cur.pit());
+               needsUpdate = cur.paragraph().dim().asc != olddim.asc ||
+                             cur.paragraph().dim().des != olddim.des ||
+                             cur.paragraph().inInset();
                if (!needsUpdate) {
                        // update only this paragraph
                        cur.bv().update(Update::SinglePar | Update::Force);
+               } else {
+                       cur.bv().update(Update::Force | Update::FitCursor);
                }
 
                bv->updateScrollbar();

Attachment: pgpzrmAVS5vvu.pgp
Description: PGP signature

Reply via email to