diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 180c2b1aa7..6ab7ac5bbc 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -415,7 +415,7 @@ bool BufferView::multiParSel() } -bool BufferView::update(Update::flags flags) +void BufferView::processUpdateFlags(Update::flags flags) { // last_inset_ points to the last visited inset. This pointer may become // invalid because of keyboard editing. Since all such operations @@ -441,12 +441,13 @@ bool BufferView::update(Update::flags flags) if (!flags) { // no need to redraw anything. metrics_info_.update_strategy = NoScreenUpdate; - return false; + return; } if (flags == Update::Decoration) { metrics_info_.update_strategy = DecorationUpdate; - return true; + buffer_.changed(); + return; } if (flags == Update::FitCursor @@ -455,15 +456,17 @@ bool BufferView::update(Update::flags flags) // tell the frontend to update the screen if needed. if (fit_cursor) { updateMetrics(false); - return true; + buffer_.changed(); + return; } if (flags & Update::Decoration) { metrics_info_.update_strategy = DecorationUpdate; - return true; + buffer_.changed(); + return; } // no screen update is needed. metrics_info_.update_strategy = NoScreenUpdate; - return false; + return; } bool full_metrics = flags & Update::Force; @@ -473,21 +476,24 @@ bool BufferView::update(Update::flags flags) bool const single_par = !full_metrics; updateMetrics(single_par); - if (flags & Update::FitCursor) { - //FIXME: updateMetrics() does not update paragraph position - // This is done at draw() time. So we need a redraw! + if (!(flags & Update::FitCursor)) { buffer_.changed(); - if (fitCursor()) - updateMetrics(false); - else - // The screen has already been updated thanks to the - // 'buffer_.changed()' call three line above. So no need - // to redraw again. - return false; + return; } - // tell the frontend to update the screen. - return true; + //FIXME: updateMetrics() does not update paragraph position + // This is done at draw() time. So we need a redraw! + buffer_.changed(); + if (!fitCursor()) + // The screen has already been updated thanks to the + // 'buffer_.changed()' call three line above. So no need + // to redraw again. + return; + + // The screen has been recentered around the cursor position so + // refresh it: + updateMetrics(false); + buffer_.changed(); } @@ -1403,11 +1409,8 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0) // If the command has been dispatched, if (cur.result().dispatched() // an update is asked, - && cur.result().update() - // and redraw is needed, - && update(cur.result().update())) - // then trigger a redraw. - buffer_.changed(); + && cur.result().update()) + processUpdateFlags(cur.result().update()); } @@ -1490,7 +1493,7 @@ void BufferView::gotoLabel(docstring const & label) it->getLabelList(buffer_, labels); if (std::find(labels.begin(), labels.end(), label) != labels.end()) { setCursor(it); - update(); + processUpdateFlags(Update::FitCursor); return; } } diff --git a/src/BufferView.h b/src/BufferView.h index 192742b8c4..9b2ef615f1 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -101,7 +101,7 @@ public: * \c Update::Force means to force an update in any case. * \retval true if a screen redraw is needed */ - bool update(Update::flags flags = Update::FitCursor | Update::Force); + void processUpdateFlags(Update::flags flags); /// move the screen to fit the cursor. /// Only to be called with good y coordinates (after a bv::metrics) diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 209f12ce18..738d799c2d 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -266,7 +266,7 @@ void LyXFunc::handleKeyFunc(kb_action action) keyseq.clear(); // copied verbatim from do_accent_char view()->cursor().resetAnchor(); - view()->update(); + view()->processUpdateFlags(Update::FitCursor); } @@ -1979,13 +1979,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) // also initializes the position cache for all insets in // (at least partially) visible top-level paragraphs. // We will redraw the screen only if needed. - if (view()->update(updateFlags)) { - // Buffer::changed() signals that a repaint is needed. - // The frontend (WorkArea) knows which area to repaint - // thanks to the ViewMetricsInfo updated above. - lyx_view_->buffer()->changed(); - } - + view()->processUpdateFlags(updateFlags); lyx_view_->updateStatusBar(); // if we executed a mutating lfun, mark the buffer as dirty diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index abc340be46..d551c22bd8 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -1724,8 +1724,7 @@ void GuiDocument::dispatchParams() "assign branch")); } // FIXME: If we used an LFUN, we would not need those two lines: - bufferview()->update(); - lyxview().currentWorkArea()->redraw(); + bufferview()->processUpdateFlags(Update::Force | Update::FitCursor); } diff --git a/src/frontends/qt4/GuiErrorList.cpp b/src/frontends/qt4/GuiErrorList.cpp index 1f135a0cff..3f9cacf2b8 100644 --- a/src/frontends/qt4/GuiErrorList.cpp +++ b/src/frontends/qt4/GuiErrorList.cpp @@ -135,9 +135,8 @@ void GuiErrorList::goTo(int item) pos_type const range = end - start; DocIterator const dit = makeDocIterator(pit, start); bufferview()->putSelectionAt(dit, range, false); - // FIXME: If we used an LFUN, we would not need those two lines: - bufferview()->update(); - lyxview().currentWorkArea()->redraw(); + // FIXME: If we used an LFUN, we would not need this line: + bufferview()->processUpdateFlags(Update::Force | Update::FitCursor); } diff --git a/src/frontends/qt4/GuiSpellchecker.cpp b/src/frontends/qt4/GuiSpellchecker.cpp index 839e580711..e3755236f0 100644 --- a/src/frontends/qt4/GuiSpellchecker.cpp +++ b/src/frontends/qt4/GuiSpellchecker.cpp @@ -378,9 +378,8 @@ void GuiSpellchecker::check() bufferview()->putSelectionAt(cur, size, false); // FIXME: if we used a lfun like in find/replace, dispatch would do // that for us - bufferview()->update(); // FIXME: this Controller is very badly designed... - lyxview().currentWorkArea()->redraw(); + bufferview()->processUpdateFlags(Update::Force | Update::FitCursor); // set suggestions if (res != SpellBase::OK && res != SpellBase::IGNORED_WORD) { @@ -434,7 +433,7 @@ void GuiSpellchecker::replace(docstring const & replacement) cap::replaceSelectionWithString(bufferview()->cursor(), replacement, true); buffer().markDirty(); // If we used an LFUN, we would not need that - bufferview()->update(); + bufferview()->processUpdateFlags(Update::Force | Update::FitCursor); // fix up the count --count_; check(); diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index dea3acd4c6..740fd284b9 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -509,7 +509,7 @@ void GuiWorkArea::updateScreen() void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape) { if (schedule_redraw_) { - buffer_view_->update(Update::Force); + buffer_view_->updateMetrics(false); updateScreen(); viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height())); schedule_redraw_ = false; diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 14760d0e33..81f9a6f1ad 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -237,7 +237,7 @@ int replace(BufferView * bv, docstring const & searchstr, cap::replaceSelectionWithString(cur, replacestr, fw); bv->buffer().markDirty(); find(bv, searchstr, cs, mw, fw, false); - bv->update(); + bv->processUpdateFlags(Update::Force | Update::FitCursor); return 1; }