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]
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;
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_)
//
// scrollDocView(new_top_y);
//
-// // Update the scrollbar.
-// workArea_->setScrollbarParams(t->height(), top_y(), defaultRowHeight());}
}
}
+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);
// 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();
}
+// FIXME: We should split-up updateMetrics() for the singlepar case.
void BufferView::updateMetrics(bool singlepar)
{
LyXText & buftext = buffer_->text();
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)
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();
}
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();
}