commit 377029920f5f6545888ceccb6cce37e63a948764 Author: Jean-Marc Lasgouttes <lasgout...@lyx.org> Date: Thu Mar 6 14:59:57 2025 +0100
Cleanup backup anchor normalization code As it was written, the code had the potential of creating new ParMetrics objects. Rewrite it to iterate over existing objects. To this end, introduce TextMetrics::begin() and TextMetrics::end(). Note how the use of C++17 structured binding declaration makes the underlying std::pair less annoying. --- src/BufferView.cpp | 5 +---- src/TextMetrics.h | 12 +++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 668c0a1c92..fd2066b867 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -3792,10 +3792,7 @@ void BufferView::draw(frontend::Painter & pain, bool paint_caret) // Normalize anchor for next time (in case updateMetrics did not do it yet) // FIXME: is this useful? - pair<pit_type, ParagraphMetrics const *> firstpm = tm.first(); - pair<pit_type, ParagraphMetrics const *> lastpm = tm.last(); - for (pit_type pit = firstpm.first; pit <= lastpm.first; ++pit) { - ParagraphMetrics const & pm = tm.parMetrics(pit); + for (auto const & [pit, pm] : tm) { if (pm.bottom() > 0) { if (d->anchor_pit_ != pit || d->anchor_ypos_ != pm.position()) diff --git a/src/TextMetrics.h b/src/TextMetrics.h index ec05b302e6..7abe9c86db 100644 --- a/src/TextMetrics.h +++ b/src/TextMetrics.h @@ -44,6 +44,14 @@ public: /// The only useful constructor. TextMetrics(BufferView *, Text *); + /// A map from paragraph index number to paragraph metrics + typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache; + + /// + ParMetricsCache::const_iterator begin() const { return par_metrics_.begin(); } + /// + ParMetricsCache::const_iterator end() const { return par_metrics_.end(); } + /// bool contains(pit_type pit) const; /// @@ -253,9 +261,7 @@ private: /// The input method instance frontend::InputMethod * im_ = nullptr; - /// A map from paragraph index number to paragraph metrics - typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache; - /// + /// FIXME: This can be changed even when TextMetrics is const mutable ParMetricsCache par_metrics_; Dimension dim_; int max_width_ = 0; -- lyx-cvs mailing list lyx-cvs@lists.lyx.org https://lists.lyx.org/mailman/listinfo/lyx-cvs