commit 7292532417a2e64ea7bac822531e3b6abca4e195
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Mon Apr 21 13:14:58 2025 +0200
Make TextMetrics hold a const pointer to Text
Only a call to Paragraph::setBodyPos() remains.
---
src/BufferView.cpp | 4 ++--
src/TextMetrics.cpp | 17 +++++++++--------
src/TextMetrics.h | 5 ++---
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 3f77c0b95b..4339e54bdd 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -3035,8 +3035,8 @@ TextMetrics & BufferView::textMetrics(Text const * t)
TextMetricsCache::iterator tmc_it = d->text_metrics_.find(t);
if (tmc_it == d->text_metrics_.end()) {
tmc_it = d->text_metrics_.emplace(std::piecewise_construct,
- std::forward_as_tuple(t),
- std::forward_as_tuple(this, const_cast<Text
*>(t))).first;
+ std::forward_as_tuple(t),
+ std::forward_as_tuple(this, t)).first;
}
return tmc_it->second;
}
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index a10cee970e..aabe2bcedb 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -108,7 +108,7 @@ int numberOfHfills(Row const & row, ParagraphMetrics const
& pm,
/////////////////////////////////////////////////////////////////////
-TextMetrics::TextMetrics(BufferView * bv, Text * text)
+TextMetrics::TextMetrics(BufferView * bv, Text const * text)
: bv_(bv), text_(text), im_(bv_->inputMethod()),
dim_(bv_->workWidth(), 10, 10), max_width_(dim_.wid)
{}
@@ -490,7 +490,7 @@ bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos,
bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
{
- Paragraph & par = text_->getPar(pit);
+ Paragraph const & par = text_->getPar(pit);
// This gets the dimension if it exists and an empty one otherwise.
Dimension old_dim = dim(pit);
ParagraphMetrics & pm = par_metrics_[pit];
@@ -521,7 +521,8 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool
const align_rows)
}
// redo insets
- par.setBeginOfBody();
+ // FIXME: contents should not be modified, move elsewhere.
+ const_cast<Paragraph &>(par).setBeginOfBody();
Font const bufferfont = buffer.params().getFont();
CoordCache::Insets & insetCache = bv_->coordCache().insets();
map <Inset const *, int> extrawidths;
@@ -1600,7 +1601,7 @@ void TextMetrics::setCursorFromCoordinates(Cursor & cur,
int x, int y)
Row const * row = getRowNearY(y);
LASSERT(row != nullptr, return);
auto [pos, bound] = getPosNearX(*row, x);
- text_->setCursor(cur, row->pit(), pos, true, bound);
+ cur.text()->setCursor(cur, row->pit(), pos, true, bound);
// remember new position.
cur.setTargetX();
}
@@ -1681,7 +1682,7 @@ bool TextMetrics::cursorHome(Cursor & cur)
LASSERT(text_ == cur.text(), return false);
ParagraphMetrics const & pm = par_metrics_[cur.pit()];
Row const & row = pm.getRow(cur.pos(),cur.boundary());
- return text_->setCursor(cur, cur.pit(), row.pos());
+ return cur.text()->setCursor(cur, cur.pit(), row.pos());
}
@@ -1705,7 +1706,7 @@ bool TextMetrics::cursorEnd(Cursor & cur)
--end;
} else if (cur.paragraph().isEnvSeparator(end-1))
--end;
- return text_->setCursor(cur, cur.pit(), end, true, boundary);
+ return cur.text()->setCursor(cur, cur.pit(), end, true, boundary);
}
@@ -1714,7 +1715,7 @@ void TextMetrics::deleteLineForward(Cursor & cur)
LASSERT(text_ == cur.text(), return);
if (cur.lastpos() == 0) {
// Paragraph is empty, so we just go forward
- text_->cursorForward(cur);
+ cur.text()->cursorForward(cur);
} else {
cur.resetAnchor();
cur.selection(true); // to avoid deletion
@@ -1722,7 +1723,7 @@ void TextMetrics::deleteLineForward(Cursor & cur)
cur.setSelection();
// What is this test for ??? (JMarc)
if (!cur.selection())
- text_->deleteWordForward(cur);
+ cur.text()->deleteWordForward(cur);
else
cap::cutSelection(cur, false);
cur.checkBufferStructure();
diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index 1109bae3cd..33c871b39b 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -40,7 +40,7 @@ public:
/// Default constructor (only here for STL containers).
TextMetrics() {}
/// The only useful constructor.
- TextMetrics(BufferView *, Text *);
+ TextMetrics(BufferView *, Text const *);
/// A map from paragraph index number to paragraph metrics
typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
@@ -253,8 +253,7 @@ private:
BufferView * bv_ = nullptr;
/// The text contents (the model).
- /// \todo FIXME: this should be const.
- Text * text_ = nullptr;
+ Text const * text_ = nullptr;
/// The input method instance
frontend::InputMethod * im_ = nullptr;
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs