Add a constructor of UndoGroupHelper that uses a CursorData parameter

This aloows to se the the `before' cursor of the undo group.

Not used for now.
This commit is contained in:
Jean-Marc Lasgouttes 2024-06-20 17:52:19 +02:00
parent f643057779
commit e7b1ee47ea
2 changed files with 22 additions and 0 deletions

View File

@ -704,6 +704,12 @@ UndoGroupHelper::UndoGroupHelper(Buffer * buf) : d(new UndoGroupHelper::Impl)
} }
UndoGroupHelper::UndoGroupHelper(CursorData & cur) : d(new UndoGroupHelper::Impl)
{
resetBuffer(cur);
}
UndoGroupHelper::~UndoGroupHelper() UndoGroupHelper::~UndoGroupHelper()
{ {
for (Buffer * buf : d->buffers_) for (Buffer * buf : d->buffers_)
@ -712,6 +718,7 @@ UndoGroupHelper::~UndoGroupHelper()
delete d; delete d;
} }
void UndoGroupHelper::resetBuffer(Buffer * buf) void UndoGroupHelper::resetBuffer(Buffer * buf)
{ {
if (buf && d->buffers_.count(buf) == 0) { if (buf && d->buffers_.count(buf) == 0) {
@ -721,4 +728,13 @@ void UndoGroupHelper::resetBuffer(Buffer * buf)
} }
void UndoGroupHelper::resetBuffer(CursorData & cur)
{
if (!cur.empty() && d->buffers_.count(cur.buffer()) == 0) {
d->buffers_.insert(cur.buffer());
cur.buffer()->undo().beginUndoGroup(cur);
}
}
} // namespace lyx } // namespace lyx

View File

@ -140,12 +140,18 @@ class UndoGroupHelper {
public: public:
// Begin a new undo group for buffer \c buf. // Begin a new undo group for buffer \c buf.
UndoGroupHelper(Buffer * buf); UndoGroupHelper(Buffer * buf);
// Begin an undo group for the buffer of \c cur with the the
// `before' cursor set to \c cur.
UndoGroupHelper(CursorData & cur);
// End all active undo groups. // End all active undo groups.
~UndoGroupHelper(); ~UndoGroupHelper();
// Begin if needed an undo group for buffer \c buf. // Begin if needed an undo group for buffer \c buf.
void resetBuffer(Buffer * buf); void resetBuffer(Buffer * buf);
// Begin if needed an undo group for the buffer of \c cur with the
// the `before' cursor set to \c cur.
void resetBuffer(CursorData & cur);
private: private:
class Impl; class Impl;
Impl * const d; Impl * const d;