]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
update comments.
[lyx.git] / src / BufferView.C
index 48444b80d2027e39c9774111a5677ecf31390538..154755c15e0105b13c812fe3866b6af956101bb1 100644 (file)
@@ -335,6 +335,10 @@ bool BufferView::multiParSel()
 
 bool BufferView::update(Update::flags flags)
 {
+       // last_inset_ points to the last visited inset. This pointer may become
+       // invalid because of keyboard editing. Since all such operations
+       // causes screen update(), I reset last_inset_ to avoid such a problem.
+       last_inset_ = 0;
        // This is close to a hot-path.
        if (lyxerr.debugging(Debug::DEBUG)) {
                lyxerr[Debug::DEBUG]
@@ -577,7 +581,6 @@ void BufferView::center()
        CursorSlice & bot = cursor_.bottom();
        TextMetrics & tm = text_metrics_[bot.text()];
        pit_type const pit = bot.pit();
-       int max_width = workWidth();
        tm.redoParagraph(pit);
        ParagraphMetrics const & pm = tm.parMetrics(pit);
        anchor_ref_ = pit;
@@ -1013,20 +1016,20 @@ void BufferView::clearSelection()
        if (buffer_) {
                cursor_.clearSelection();
                xsel_cache_.set = false;
+               // The buffer did not really change, but this causes the
+               // redraw we need because we cleared the selection above.
+               buffer_->changed();
        }
 }
 
 
 void BufferView::workAreaResize(int width, int height)
 {
-       // A resize is triggered whenever a window gets focus,
-       // because of the shared rows() of a buffer in multiple
-       // buffer views.
-       
        // Update from work area
        width_ = width;
        height_ = height;
 
+       // The complete text metrics will be redone.
        text_metrics_.clear();
 
        if (buffer_)
@@ -1149,8 +1152,6 @@ void BufferView::scroll(int /*lines*/)
 //
 //     scrollDocView(new_top_y);
 //
-//     // Update the scrollbar.
-//     workArea_->setScrollbarParams(t->height(), top_y(), defaultRowHeight());}
 }
 
 
@@ -1239,6 +1240,28 @@ void BufferView::setCursor(DocIterator const & dit)
 }
 
 
+bool BufferView::checkDepm(LCursor & cur, LCursor & old)
+{
+       // Would be wrong to delete anything if we have a selection.
+       if (cur.selection())
+               return false;
+
+       bool need_anchor_change = false;
+       bool changed = cursor_.text()->deleteEmptyParagraphMechanism(cur, old,
+               need_anchor_change);
+
+       if (need_anchor_change)
+               cur.resetAnchor();
+       
+       if (!changed)
+               return false;
+
+       updateMetrics(false);
+       buffer_->changed();
+       return true;
+}
+
+
 bool BufferView::mouseSetCursor(LCursor & cur)
 {
        BOOST_ASSERT(&cur.bv() == this);
@@ -1252,7 +1275,7 @@ bool BufferView::mouseSetCursor(LCursor & cur)
        // FIXME: move this to InsetText::notifyCursorLeaves?
        bool update = false;
        if (!badcursor && cursor_.inTexted())
-               update = cursor_.text()->deleteEmptyParagraphMechanism(cur, cursor_);
+               checkDepm(cur, cursor_);
 
        cursor_ = cur;
        cursor_.clearSelection();
@@ -1303,6 +1326,7 @@ ViewMetricsInfo const & BufferView::viewMetricsInfo()
 }
 
 
+// FIXME: We should split-up updateMetrics() for the singlepar case.
 void BufferView::updateMetrics(bool singlepar)
 {
        LyXText & buftext = buffer_->text();
@@ -1313,19 +1337,25 @@ void BufferView::updateMetrics(bool singlepar)
                anchor_ref_ = int(buftext.paragraphs().size() - 1);
                offset_ref_ = 0;
        }
+       
+       // If the paragraph metrics has changed, we can not
+       // use the singlepar optimisation.
+       if (singlepar
+               // In Single Paragraph mode, rebreak only
+               // the (main text, not inset!) paragraph containing the cursor.
+               // (if this paragraph contains insets etc., rebreaking will
+               // recursively descend)
+               && tm.redoParagraph(cursor_.bottom().pit()))
+               singlepar = false;
 
        pit_type const pit = anchor_ref_;
        int pit1 = pit;
        int pit2 = pit;
        size_t const npit = buftext.paragraphs().size();
 
-       // Rebreak anchor paragraph. In Single Paragraph mode, rebreak only
-       // the (main text, not inset!) paragraph containing the cursor.
-       // (if this paragraph contains insets etc., rebreaking will
-       // recursively descend)
-       if (!singlepar || pit == cursor_.bottom().pit())
-               if (tm.redoParagraph(pit))
-                       singlepar = false;
+       // Rebreak anchor paragraph.
+       if (!singlepar)
+               tm.redoParagraph(pit);
        
        // Clear out the position cache in case of full screen redraw.
        if (!singlepar)
@@ -1333,13 +1363,12 @@ void BufferView::updateMetrics(bool singlepar)
 
        int y0 = tm.parMetrics(pit).ascent() - offset_ref_;
 
-       // Redo paragraphs above anchor if necessary; again, in Single Par
-       // mode, only if we encounter the (main text) one having the cursor.
+       // Redo paragraphs above anchor if necessary.
        int y1 = y0;
        while (y1 > 0 && pit1 > 0) {
                y1 -= tm.parMetrics(pit1).ascent();
                --pit1;
-               if (!singlepar || pit1 == cursor_.bottom().pit())
+               if (!singlepar)
                        tm.redoParagraph(pit1);
                y1 -= tm.parMetrics(pit1).descent();
        }
@@ -1359,13 +1388,12 @@ void BufferView::updateMetrics(bool singlepar)
                anchor_ref_ = 0;
        }
 
-       // Redo paragraphs below the anchor if necessary. Single par mode:
-       // only the one containing the cursor if encountered.
+       // Redo paragraphs below the anchor if necessary.
        int y2 = y0;
        while (y2 < height_ && pit2 < int(npit) - 1) {
                y2 += tm.parMetrics(pit2).descent();
                ++pit2;
-               if (!singlepar || pit2 == cursor_.bottom().pit())
+               if (!singlepar)
                        tm.redoParagraph(pit2);
                y2 += tm.parMetrics(pit2).ascent();
        }