X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBufferView.cpp;h=e316aab02e2d38319d2d5dd6df5d7cabb106a90d;hb=294e4884ee29585d311177406cd31499e6d81877;hp=ca59fcb4db9f3c0878bd43641b614a181c4fe22a;hpb=b9e29418471d0d275650c52f976da300f4f42501;p=lyx.git diff --git a/src/BufferView.cpp b/src/BufferView.cpp index ca59fcb4db..e316aab02e 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -35,7 +35,6 @@ #include "Language.h" #include "LaTeXFeatures.h" #include "LayoutFile.h" -#include "Length.h" #include "Lexer.h" #include "LyX.h" #include "LyXAction.h" @@ -81,6 +80,7 @@ #include "support/filetools.h" #include "support/gettext.h" #include "support/lassert.h" +#include "support/Length.h" #include "support/lstrings.h" #include "support/lyxlib.h" #include "support/Package.h" @@ -179,13 +179,6 @@ bool findInset(DocIterator & dit, vector const & codes, } -/// Looks for next inset with the given code -void findInset(DocIterator & dit, InsetCode code, bool same_content) -{ - findInset(dit, vector(1, code), same_content); -} - - /// Moves cursor to the next inset with one of the given codes. void gotoInset(BufferView * bv, vector const & codes, bool same_content) @@ -202,13 +195,6 @@ void gotoInset(BufferView * bv, vector const & codes, } -/// Moves cursor to the next inset with given code. -void gotoInset(BufferView * bv, InsetCode code, bool same_content) -{ - gotoInset(bv, vector(1, code), same_content); -} - - /// A map from a Text to the associated text metrics typedef map TextMetricsCache; @@ -374,6 +360,20 @@ int BufferView::leftMargin() const } +int BufferView::topMargin() const +{ + // original value was 20px, which is 0.2in at 100dpi + return zoomedPixels(20); +} + + +int BufferView::bottomMargin() const +{ + // original value was 20px, which is 0.2in at 100dpi + return zoomedPixels(20); +} + + int BufferView::inPixels(Length const & len) const { Font const font = buffer().params().getFont(); @@ -1530,14 +1530,19 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) } case LFUN_NOTE_NEXT: - gotoInset(this, NOTE_CODE, false); + gotoInset(this, { NOTE_CODE }, false); + // FIXME: if SinglePar is changed to act on the inner + // paragraph, this will not be OK anymore. The update is + // useful for auto-open collapsible insets. + dr.screenUpdate(Update::SinglePar | Update::FitCursor); break; case LFUN_REFERENCE_NEXT: { - vector tmp; - tmp.push_back(LABEL_CODE); - tmp.push_back(REF_CODE); - gotoInset(this, tmp, true); + gotoInset(this, { LABEL_CODE, REF_CODE }, true); + // FIXME: if SinglePar is changed to act on the inner + // paragraph, this will not be OK anymore. The update is + // useful for auto-open collapsible insets. + dr.screenUpdate(Update::SinglePar | Update::FitCursor); break; } @@ -1715,7 +1720,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_BIBTEX_DATABASE_ADD: { Cursor tmpcur = cur; - findInset(tmpcur, BIBTEX_CODE, false); + findInset(tmpcur, { BIBTEX_CODE }, false); InsetBibtex * inset = getInsetByCode(tmpcur, BIBTEX_CODE); if (inset) { @@ -1727,7 +1732,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) case LFUN_BIBTEX_DATABASE_DEL: { Cursor tmpcur = cur; - findInset(tmpcur, BIBTEX_CODE, false); + findInset(tmpcur, { BIBTEX_CODE }, false); InsetBibtex * inset = getInsetByCode(tmpcur, BIBTEX_CODE); if (inset) { @@ -2772,7 +2777,7 @@ bool BufferView::singleParUpdate() Text & buftext = buffer_.text(); pit_type const bottom_pit = d->cursor_.bottom().pit(); TextMetrics & tm = textMetrics(&buftext); - int old_height = tm.parMetrics(bottom_pit).height(); + Dimension const old_dim = tm.parMetrics(bottom_pit).dim(); // make sure inline completion pointer is ok if (d->inlineCompletionPos_.fixIfBroken()) @@ -2783,11 +2788,16 @@ bool BufferView::singleParUpdate() // (if this paragraph contains insets etc., rebreaking will // recursively descend) tm.redoParagraph(bottom_pit); - ParagraphMetrics const & pm = tm.parMetrics(bottom_pit); - if (pm.height() != old_height) + ParagraphMetrics & pm = tm.parMetrics(bottom_pit); + if (pm.height() != old_dim.height()) { // Paragraph height has changed so we cannot proceed to // the singlePar optimisation. return false; + } + // Since position() points to the baseline of the first row, we + // may have to update it. See ticket #11601 for an example where + // the height does not change but the ascent does. + pm.setPosition(pm.position() - old_dim.ascent() + pm.ascent()); tm.updatePosCache(bottom_pit); @@ -2835,7 +2845,7 @@ void BufferView::updateMetrics(Update::flags & update_flags) // Rebreak anchor paragraph. tm.redoParagraph(d->anchor_pit_); - ParagraphMetrics & anchor_pm = tm.par_metrics_[d->anchor_pit_]; + ParagraphMetrics & anchor_pm = tm.parMetrics(d->anchor_pit_); // position anchor if (d->anchor_pit_ == 0) { @@ -2860,17 +2870,14 @@ void BufferView::updateMetrics(Update::flags & update_flags) int y1 = d->anchor_ypos_ - anchor_pm.ascent(); // We are now just above the anchor paragraph. pit_type pit1 = d->anchor_pit_ - 1; - while (y1 >= 0) { + for (; pit1 >= 0 && y1 >= 0; --pit1) { tm.redoParagraph(pit1); - ParagraphMetrics & pm = tm.par_metrics_[pit1]; + ParagraphMetrics & pm = tm.parMetrics(pit1); y1 -= pm.descent(); // Save the paragraph position in the cache. pm.setPosition(y1); tm.updatePosCache(pit1); y1 -= pm.ascent(); - if (pit1 == 0) - break; - --pit1; } // Redo paragraphs below the anchor if necessary. @@ -2879,7 +2886,7 @@ void BufferView::updateMetrics(Update::flags & update_flags) pit_type pit2 = d->anchor_pit_ + 1; for (; pit2 < npit && y2 <= height_; ++pit2) { tm.redoParagraph(pit2); - ParagraphMetrics & pm = tm.par_metrics_[pit2]; + ParagraphMetrics & pm = tm.parMetrics(pit2); y2 += pm.ascent(); // Save the paragraph position in the cache. pm.setPosition(y2);