mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 02:49:46 +00:00
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:
parent
9b4b05e64e
commit
21096f696a
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user