]> git.lyx.org Git - lyx.git/commitdiff
Sanitize cursors after a buffer has been reloaded
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 16 Apr 2024 09:45:09 +0000 (11:45 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 16 Apr 2024 21:48:01 +0000 (23:48 +0200)
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().

src/Buffer.cpp
src/frontends/WorkArea.h
src/frontends/WorkAreaManager.cpp
src/frontends/WorkAreaManager.h
src/frontends/qt/GuiWorkArea.h

index bbe4d80589651fa2bf86bcc6a7029c153e7dd408..c9d6818df6d56eba46bb691a4c83a5f69e150ba5 100644 (file)
@@ -5562,6 +5562,8 @@ 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();
index d6912fc7fad982d59ba7ec90675ff970eee0a4e8..c0e673554a58e05009fe12fbfe8b689eada5f9e4 100644 (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
index 8d32c6b6d8101a2dab686c01df1c64f9a821f3e2..324d5571afe66bcfa51556130d4ce1e5989222bd 100644 (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
 
index 94c528b3a69858da58c3ed1e40090603b678f218..73548592fa719512fdeb58ffd7ed5cc0bfd751ee 100644 (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;
index 148b79b73aaff257c908884c890166e4aa6befa8..86bbfda93906bf6ded27c5f790b77c96dc2b6204 100644 (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;