Sanitize cursors after a buffer has been reloaded

When a buffer is reloaded, its content may remain the same, but the
memory allocation is new, so that the inset pointers in cursors are
now wrong. This requires to sanitize the cursors held by the buffer
views.

Before the biginset branch, some full metrics computation call that is
now removed probably did that as a side effect. Now we have to be more
precise.

To this effect, introduce WorkAreaManager::sanitizeCursors() and use
it in Buffer::reload().

(cherry picked from commit c1fd622c51)
This commit is contained in:
Jean-Marc Lasgouttes 2024-04-16 11:45:09 +02:00
parent 9b4b05e64e
commit 21096f696a
5 changed files with 26 additions and 2 deletions

View File

@ -5562,6 +5562,9 @@ Buffer::ReadStatus Buffer::reload()
Buffer const * oldparent = d->parent();
d->setParent(nullptr);
ReadStatus const status = loadLyXFile();
// The inset members in cursors held by buffer views are now wrong.
workAreaManager().sanitizeCursors();
setBusy(false);
if (status == ReadSuccess) {
updateBuffer();
changed(true);

View File

@ -18,6 +18,8 @@
namespace lyx {
class BufferView;
namespace frontend {
/**
@ -40,6 +42,11 @@ public:
/// Update window titles of all users.
virtual void updateWindowTitle() = 0;
///
virtual BufferView & bufferView() = 0;
///
virtual BufferView const & bufferView() const = 0;
};
} // namespace frontend

View File

@ -13,6 +13,9 @@
#include "WorkAreaManager.h"
#include "BufferView.h"
#include "Cursor.h"
#include "Application.h"
#include "WorkArea.h"
@ -69,6 +72,15 @@ void WorkAreaManager::scheduleRedraw()
}
void WorkAreaManager::sanitizeCursors()
{
for (WorkArea * wa : work_areas_) {
wa->bufferView().cursor().sanitize();
wa->bufferView().resetInlineCompletionPos();
}
}
} // namespace frontend
} // namespace lyx

View File

@ -49,6 +49,8 @@ public:
/// If there is no work area, create a new one in the current view using the
/// buffer buf. Returns false if not possible.
bool unhide(Buffer * buf) const;
/// Fix cursors in all buffer views held by work areas.
void sanitizeCursors();
private:
typedef std::list<WorkArea *>::iterator iterator;

View File

@ -59,9 +59,9 @@ public:
/// is GuiView in fullscreen mode?
bool isFullScreen() const;
///
BufferView & bufferView();
BufferView & bufferView() override;
///
BufferView const & bufferView() const;
BufferView const & bufferView() const override;
///
void scheduleRedraw(bool update_metrics) override;