mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-29 13:04:58 +00:00
Use the proper buffer when recording undo
The code in InsetLabel::updateReferences code changes reference insets in potentially several buffers. When recording undo, it is important to use the right undo stack, otherwise crashes can ensue. Once it is done, it is neccessary to create undo groups as needed. This is done using UndoGroupHelper. This demonstrates a shortcoming of UndoGroup helper: if a buffer is encountered in two seperate occasions, two undo groups will be created for this buffer. This is not correct. Fixes bug #10643.
This commit is contained in:
parent
fd5a950d7f
commit
4eb9b50dc6
@ -643,6 +643,13 @@ void Undo::recordUndoFullBuffer(CursorData const & cur)
|
|||||||
|
|
||||||
/// UndoGroupHelper class stuff
|
/// UndoGroupHelper class stuff
|
||||||
|
|
||||||
|
/** FIXME: handle restarted groups
|
||||||
|
* It may happen that the buffers are visited in order buffer1,
|
||||||
|
* buffer2, buffer1. In this case, we want to have only one undo group
|
||||||
|
* in buffer1. One solution is to replace buffer_ with a set<Buffer*>,
|
||||||
|
* but I am not sure yet how to do it. A use case is
|
||||||
|
* InsetLabel::updateReferences.
|
||||||
|
*/
|
||||||
void UndoGroupHelper::resetBuffer(Buffer * buf)
|
void UndoGroupHelper::resetBuffer(Buffer * buf)
|
||||||
{
|
{
|
||||||
if (buf == buffer_)
|
if (buf == buffer_)
|
||||||
|
@ -135,7 +135,7 @@ private:
|
|||||||
*/
|
*/
|
||||||
class UndoGroupHelper {
|
class UndoGroupHelper {
|
||||||
public:
|
public:
|
||||||
UndoGroupHelper(Buffer * buf) : buffer_(0)
|
UndoGroupHelper(Buffer * buf = 0) : buffer_(0)
|
||||||
{
|
{
|
||||||
resetBuffer(buf);
|
resetBuffer(buf);
|
||||||
}
|
}
|
||||||
|
@ -109,11 +109,13 @@ void InsetLabel::updateLabelAndRefs(docstring const & new_label,
|
|||||||
void InsetLabel::updateReferences(docstring const & old_label,
|
void InsetLabel::updateReferences(docstring const & old_label,
|
||||||
docstring const & new_label)
|
docstring const & new_label)
|
||||||
{
|
{
|
||||||
|
UndoGroupHelper ugh;
|
||||||
Buffer::References const & refs = buffer().references(old_label);
|
Buffer::References const & refs = buffer().references(old_label);
|
||||||
Buffer::References::const_iterator it = refs.begin();
|
Buffer::References::const_iterator it = refs.begin();
|
||||||
Buffer::References::const_iterator end = refs.end();
|
Buffer::References::const_iterator end = refs.end();
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
buffer().undo().recordUndo(CursorData(it->second));
|
ugh.resetBuffer(it->second.buffer());
|
||||||
|
it->second.buffer()->undo().recordUndo(CursorData(it->second));
|
||||||
if (it->first->lyxCode() == MATH_REF_CODE) {
|
if (it->first->lyxCode() == MATH_REF_CODE) {
|
||||||
InsetMathRef * mi = it->first->asInsetMath()->asRefInset();
|
InsetMathRef * mi = it->first->asInsetMath()->asRefInset();
|
||||||
mi->changeTarget(new_label);
|
mi->changeTarget(new_label);
|
||||||
|
Loading…
Reference in New Issue
Block a user