On Fri, May 13, 2005 at 10:59:44PM +0200, Andre Poenitz wrote:
> On Fri, May 13, 2005 at 09:46:29PM +0300, Martin Vermeer wrote:
> > Actually it should be noted that paintText called from LyXScreen::redraw
> > still draws _three_ paragraphs: the one containing the cursor, and the 
> > ones above and below, see rowpainter.C. I'm sure there is a good reason
> > for this when redrawing the whole screen...
> 
> We need up-to-date metrics in the paragraph below to handle e.g. <Down>
> when the cursor is in the last line of a paragraph. 
> 
> I think this was the reason before the null painter was invented...
> 
> > we could easily propagate the bool onlypar (by adding it to
> > ViewMetricsInfo?) to prevent also this, giving a further speed-up.
> > 
> > Is this a sensible direction?
> 
> I think so.
> 
> > -void BufferView::update(bool fitcursor, bool forceupdate)
> > +void BufferView::update(bool fitcursor, bool forceupdate, bool onlypar)
> >  {
> > -   pimpl_->update(fitcursor, forceupdate);
> > +   pimpl_->update(fitcursor, forceupdate, onlypar);
> >  }
> 
> Pretty much looks like the old update flags now. I knew there must have
> been a reason...
> 
> enum UpdateFlags { UpdateFitCursor = 1, UpdateForce = 2, UpdateOnlyPar =
> 4 };
> 
>  +    void update(UpdateFlags = UpdateFitCursor | UpdateForce);
> 
> 
> This makes things like
> 
> > +                   cur.bv().update(false, true, true);
> 
> a bit mmore readble:
> 
>                       cur.bv().update(UpdateForce | UpdateOnlyPar);
> 
> Andre'

So here is the patch again... OK to commit?

- Martin


Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.2182
diff -u -p -r1.2182 ChangeLog
--- ChangeLog   12 May 2005 12:22:35 -0000      1.2182
+++ ChangeLog   15 May 2005 08:51:40 -0000
@@ -1,3 +1,16 @@
+2005-05-15  Martin Vermeer  <[EMAIL PROTECTED]>
+
+       * BufferView.[Ch] (update):
+       * BufferView_pimpl.[Ch] (update, metrics):
+       * dimension.h (operator==):
+       * lyxfunc.C (dispatch):
+       * metricsinfo.h (ViewMetricsInfo):
+       * rowpainter.C (paintText):
+       * lyxtext.h:
+       * text.C (redoParagraph): 
+       * text3.C (dispatch): Make LyX only repaint current paragraph in
+       case of character insert --> speedup
+
 2005-05-12  Martin Vermeer  <[EMAIL PROTECTED]>
 
        * tabular.[hC]: added setCellInset to fix tabular paste.
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.260
diff -u -p -r1.260 BufferView.C
--- BufferView.C        22 Feb 2005 11:41:19 -0000      1.260
+++ BufferView.C        15 May 2005 08:51:40 -0000
@@ -142,9 +142,9 @@ bool BufferView::fitCursor()
 }
 
 
-void BufferView::update(bool fitcursor, bool forceupdate)
+void BufferView::update(int updateflags)
 {
-       pimpl_->update(fitcursor, forceupdate);
+       pimpl_->update(updateflags);
 }
 
 
Index: BufferView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v
retrieving revision 1.186
diff -u -p -r1.186 BufferView.h
--- BufferView.h        26 Apr 2005 11:12:09 -0000      1.186
+++ BufferView.h        15 May 2005 08:51:40 -0000
@@ -81,7 +81,14 @@ public:
         *  position changes. \c forceupdate means to force an update
         *  in any case.
         */
-       void update(bool fitcursor = true, bool forceupdate = true);
+
+       enum UpdateFlags { 
+               UpdateFitCursor = 1, 
+               UpdateForce = 2,
+               UpdateSinglePar = 4 
+       };
+
+       void update(int updateflags = UpdateFitCursor | UpdateForce);
        /// move the screen to fit the cursor. Only to be called with
        /// good y coordinates (after a bv::metrics)
        bool fitCursor();
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.583
diff -u -p -r1.583 BufferView_pimpl.C
--- BufferView_pimpl.C  11 May 2005 07:44:18 -0000      1.583
+++ BufferView_pimpl.C  15 May 2005 08:51:40 -0000
@@ -606,11 +606,12 @@ bool BufferView::Pimpl::fitCursor()
 }
 
 
-void BufferView::Pimpl::update(bool fitcursor, bool forceupdate)
+void BufferView::Pimpl::update(int updateflags)
 {
        lyxerr << BOOST_CURRENT_FUNCTION
-              << "[fitcursor = " << fitcursor << ','
-              << " forceupdate = " << forceupdate
+              << "[fitcursor = " << (updateflags & UpdateFitCursor)
+              << ", forceupdate = " << (updateflags & UpdateForce)
+              << ", singlepar = " << (updateflags & UpdateSinglePar)
               << "]  buffer: " << buffer_ << endl;
 
        // Check needed to survive LyX startup
@@ -632,10 +633,11 @@ void BufferView::Pimpl::update(bool fitc
 
                // First drawing step
                ViewMetricsInfo vi = metrics();
+               bool forceupdate(updateflags & UpdateForce);
 
-               if (fitcursor && fitCursor()) {
+               if ((updateflags & UpdateFitCursor) && fitCursor()) {
                        forceupdate = true;
-                       vi = metrics();
+                       vi = metrics(updateflags & UpdateSinglePar);
                }
                if (forceupdate) {
                        // Second drawing step
@@ -934,7 +936,10 @@ bool BufferView::Pimpl::workAreaDispatch
 
        if (cur.result().dispatched()) {
                // Redraw if requested or necessary.
-               update(cur.result().update(), cur.result().update());
+               if (cur.result().update())
+                       update(UpdateFitCursor | UpdateForce);
+               else
+                       update();
        }
 
        // See workAreaKeyPress
@@ -1246,7 +1251,7 @@ bool BufferView::Pimpl::dispatch(FuncReq
 }
 
 
-ViewMetricsInfo BufferView::Pimpl::metrics()
+ViewMetricsInfo BufferView::Pimpl::metrics(bool singlepar)
 {
        // Remove old position cache
        theCoords.clear();
@@ -1274,7 +1279,7 @@ ViewMetricsInfo BufferView::Pimpl::metri
 
        // Redo paragraphs above cursor if necessary
        int y1 = y0;
-       while (y1 > 0 && pit1 > 0) {
+       while (!singlepar && y1 > 0 && pit1 > 0) {
                y1 -= text->getPar(pit1).ascent();
                --pit1;
                text->redoParagraph(pit1);
@@ -1298,7 +1303,7 @@ ViewMetricsInfo BufferView::Pimpl::metri
 
        // Redo paragraphs below cursor if necessary
        int y2 = y0;
-       while (y2 < bv.workHeight() && pit2 < int(npit) - 1) {
+       while (!singlepar && y2 < bv.workHeight() && pit2 < int(npit) - 1) {
                y2 += text->getPar(pit2).descent();
                ++pit2;
                text->redoParagraph(pit2);
@@ -1321,5 +1326,5 @@ ViewMetricsInfo BufferView::Pimpl::metri
               << " y2: " << y2
               << endl;
 
-       return ViewMetricsInfo(pit1, pit2, y1, y2);
+       return ViewMetricsInfo(pit1, pit2, y1, y2, singlepar);
 }
Index: BufferView_pimpl.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.h,v
retrieving revision 1.127
diff -u -p -r1.127 BufferView_pimpl.h
--- BufferView_pimpl.h  19 Jan 2005 15:03:26 -0000      1.127
+++ BufferView_pimpl.h  15 May 2005 08:51:40 -0000
@@ -60,7 +60,7 @@ public:
        //
        bool fitCursor();
        ///
-       void update(bool fitcursor = false, bool forceupdate = true);
+       void update(int updateflags = UpdateForce);
        ///
        void newFile(std::string const &, std::string const &, bool);
        ///
@@ -186,7 +186,7 @@ private:
        ///
        int offset_ref_;
        ///
-       ViewMetricsInfo metrics();
+       ViewMetricsInfo metrics(bool singlepar = false);
 
 
 };
Index: dimension.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/dimension.h,v
retrieving revision 1.6
diff -u -p -r1.6 dimension.h
--- dimension.h 18 Jan 2005 14:15:55 -0000      1.6
+++ dimension.h 15 May 2005 08:51:40 -0000
@@ -61,4 +61,10 @@ public:
        int des;
 };
 
+inline
+bool operator==(Dimension const & a, Dimension const & b)
+{
+       return a.wid == b.wid && a.asc == b.asc && a.des ==b.des ;
+}
+
 #endif
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.657
diff -u -p -r1.657 lyxfunc.C
--- lyxfunc.C   6 May 2005 20:00:30 -0000       1.657
+++ lyxfunc.C   15 May 2005 08:51:41 -0000
@@ -1522,7 +1522,11 @@ void LyXFunc::dispatch(FuncRequest const
                        // Redraw screen unless explicitly told otherwise.
                        // This also initializes the position cache for all 
insets
                        // in (at least partially) visible top-level paragraphs.
-                       view()->update(true, update);
+                       if (update)
+                               view()->update(BufferView::UpdateFitCursor 
+                                            | BufferView::UpdateForce);
+                       else
+                               view()->update(BufferView::UpdateFitCursor);
 
                        // if we executed a mutating lfun, mark the buffer as 
dirty
                        // FIXME: Why not use flag.enabled() but call getStatus 
again?
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.321
diff -u -p -r1.321 lyxtext.h
--- lyxtext.h   12 Apr 2005 18:42:24 -0000      1.321
+++ lyxtext.h   15 May 2005 08:51:41 -0000
@@ -95,7 +95,7 @@ public:
        void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
 
        /// rebreaks the given par
-       void redoParagraph(pit_type pit);
+       bool redoParagraph(pit_type pit);
 
        /// returns pos in given par at given x coord
        pos_type x2pos(pit_type pit, int row, int x) const;
Index: metricsinfo.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/metricsinfo.h,v
retrieving revision 1.15
diff -u -p -r1.15 metricsinfo.h
--- metricsinfo.h       19 Jan 2005 15:03:29 -0000      1.15
+++ metricsinfo.h       15 May 2005 08:51:41 -0000
@@ -97,12 +97,14 @@ class TextMetricsInfo {};
 class ViewMetricsInfo
 {
 public:
-       ViewMetricsInfo(lyx::pit_type p1, lyx::pit_type p2,
-                       int y1, int y2) : p1(p1), p2(p2), y1(y1), y2(y2) {}
+       ViewMetricsInfo(lyx::pit_type p1, lyx::pit_type p2, int y1, int y2, 
+                       bool singlepar) : p1(p1), p2(p2), y1(y1), y2(y2),
+                       singlepar(singlepar) {}
        lyx::pit_type p1;
        lyx::pit_type p2;
        int y1;
        int y2;
+       bool singlepar;
 };
 
 
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.149
diff -u -p -r1.149 rowpainter.C
--- rowpainter.C        5 May 2005 13:11:05 -0000       1.149
+++ rowpainter.C        15 May 2005 08:51:41 -0000
@@ -785,18 +785,19 @@ void paintText(BufferView const & bv, Vi
                yy += text->getPar(pit).descent();
        }
 
+       if (!vi.singlepar) {
+               // paint one paragraph above and one below
+               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());
+               }
 
-       // paint one paragraph above and one below
-       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());
-       }
-
-       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());
+               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());
+               }
        }
 
        // and grey out above (should not happen later)
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.293
diff -u -p -r1.293 text3.C
--- text3.C     5 May 2005 13:13:56 -0000       1.293
+++ text3.C     15 May 2005 08:51:41 -0000
@@ -262,7 +262,7 @@ void update(LCursor & cur)
 {
        //we don't call update(true, false) directly to save a metrics call
        if (cur.bv().fitCursor())
-               cur.bv().update(false, true);
+               cur.bv().update(BufferView::UpdateForce);
 }
 
 
@@ -1129,9 +1129,14 @@ void LyXText::dispatch(LCursor & cur, Fu
                cur.resetAnchor();
                moveCursor(cur, false);
 
+               needsUpdate = redoParagraph(cur.pit());
+               if (!needsUpdate)
+                       // update only this paragraph
+                       cur.bv().update(BufferView::UpdateSinglePar
+                                     | BufferView::UpdateForce);
+
                // real_current_font.number can change so we need to
                // update the minibuffer
-               if (old_font != real_current_font)
                bv->updateScrollbar();
                break;
        }
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.601
diff -u -p -r1.601 text.C
--- text.C      5 May 2005 18:33:47 -0000       1.601
+++ text.C      15 May 2005 08:51:41 -0000
@@ -1649,7 +1649,7 @@ Row const & LyXText::firstRow() const
 }
 
 
-void LyXText::redoParagraph(pit_type const pit)
+bool LyXText::redoParagraph(pit_type const pit)
 {
        // remove rows of paragraph, keep track of height changes
        Paragraph & par = pars_[pit];
@@ -1700,8 +1700,13 @@ void LyXText::redoParagraph(pit_type con
 
        dim.asc += par.rows()[0].ascent();
        dim.des -= par.rows()[0].ascent();
+       
+       bool const same = dim == par.dim();
+
        par.dim() = dim;
        //lyxerr << "redoParagraph: " << par.rows().size() << " rows\n";
+
+       return !same;
 }
 
 

Attachment: pgp2Jc2Omq6Iy.pgp
Description: PGP signature

Reply via email to