commit b8c0c408597a45ca26f313c043be39af3ca1cff9
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Wed Apr 9 15:43:05 2025 +0200
Move fixBiblio to updateBuffer (1/4) : Add new method helper method
Introduce new method DocIterator::updateAfterInsertion. This method
updates the DocIterator after a modification happened at another
DocIterator position.
It is not used yet. Eventually, it will be used to update cursors in
all views.
---
src/DocIterator.cpp | 25 +++++++++++++++++++++++++
src/DocIterator.h | 5 +++++
2 files changed, 30 insertions(+)
diff --git a/src/DocIterator.cpp b/src/DocIterator.cpp
index 131a403c13..7d18c36547 100644
--- a/src/DocIterator.cpp
+++ b/src/DocIterator.cpp
@@ -649,6 +649,31 @@ void DocIterator::sanitize()
}
+void DocIterator::updateAfterInsertion(DocIterator const & dit, int const
count)
+{
+ LASSERT(dit.inTexted(), return);
+ size_type const n = find(&dit.inset());
+ if (n == lyx::npos)
+ // we do not point to the inset where this happened.
+ return;
+ CursorSlice & sl = slices_[n];
+ if (sl.idx() != dit.idx() || sl.pit() != dit.pit() || sl.pos() <
dit.pos())
+ // the change has been happening in a place that we do not care
about.
+ return;
+
+ if (count < 0 && sl.pos() < dit.pos() - count) {
+ if (n + 1 < slices_.size())
+ // the inset we pointed to has been chopped-off.
+ resize(n + 1);
+ else
+ // set cursor at the start of deleted part.
+ sl.pos() = dit.pos();
+ } else
+ // adapt cursor position.
+ sl.pos() += count;
+}
+
+
bool DocIterator::isInside(Inset const * p) const
{
for (CursorSlice const & sl : slices_)
diff --git a/src/DocIterator.h b/src/DocIterator.h
index 06be32fba1..f46d57598f 100644
--- a/src/DocIterator.h
+++ b/src/DocIterator.h
@@ -251,6 +251,11 @@ public:
/// Repopulate the slices insets from bottom to top. Useful
/// for stable iterators or Undo data.
void sanitize();
+ /** Update the iterator after an insertion or a deletion
+ * \param dit : the place where the insertion happened.
+ * \param count : the number of characters added (or deleted if
negative).
+ */
+ void updateAfterInsertion(DocIterator const & dit, int count = 1);
///
bool isInside(Inset const *) const;
/// make sure we are outside of given inset
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs