Commit Graph

93 Commits

Author SHA1 Message Date
Richard Kimberly Heck
946d112ee6 Allow to call cap::switchBetweenClasses without an ErrorList.
It turns out that we usually don't care about the errors and so
were creating dummy ErrorList objects in several places.
2021-02-25 21:49:50 -05:00
Jean-Marc Lasgouttes
3e3ad2937c Remove assertion that is not necessary.
It may happen that there are errors when doing undo, crashing does not
help in this case.

Fixes bug #12163.
2021-02-25 20:00:41 +01:00
Yuriy Skalko
9cb98136ce Cleanup headers 2020-12-03 00:38:27 +02:00
Yuriy Skalko
ecf62a8f21 Refactor OutputParams
Now all Inset hierarchy uses OutputParams.h included in Inset.h.
Forward declare some enums to reduce header dependencies.
2020-11-30 13:05:03 +02:00
Yuriy Skalko
196d9caeb0 Clean includes using the output of iwyu tool 2020-10-20 11:38:55 +03:00
Richard Kimberly Heck
3b2bcef455 Fix some warnings. 2020-05-03 02:46:11 -04:00
Jean-Marc Lasgouttes
714113655a Follow some of the performance advice from cppcheck
Most of that is changing string to string const &.
2019-09-13 16:23:49 +02:00
Jean-Marc Lasgouttes
64396717db Allow to undo partly math autocorrect
To this end, introduce Undo::splitUndoGroup, which ends currently
group and creates a new one with same nesting level.
2019-06-02 21:17:26 +02:00
Jean-Marc Lasgouttes
8e3972c35d Revert "Allow to undo partly math autocorrect"
This reverts commit f7a11ca711.
2019-04-16 16:03:57 +02:00
Jean-Marc Lasgouttes
f7a11ca711 Allow to undo partly math autocorrect
To this end, introduce Undo::splitUndoGroup, which ends currently
group and creates a new one with same nesting level.
2019-04-16 14:12:34 +02:00
Jean-Marc Lasgouttes
86398b5d91 Cleanup: Rename textUndo to undoAction
This is not limited to text, but also handles math.

Same change to textRedo.
2018-08-30 14:17:53 +02:00
Jean-Marc Lasgouttes
4d0c43f9aa Fixup c7496a11: test emptiness before accessing elements 2018-06-01 21:48:26 +02:00
Jean-Marc Lasgouttes
c7496a11b2 Skip paint event when in the middle of a buffer operation
This is detected when an undo group is open and contains at east one
element. This means indeed that changes are in progress. Note that the
group is in general opened in GuiApplication::dispatch. The code there
is changed to ensure that the group is closed before updating the
screen.

This patch is experimental. It is expected to be replaced in master by
a more complete solution. It could in the meantime be backported to 2.3.x.

Fixes bug #11159.
2018-05-31 23:26:17 +02:00
Richard Kimberly Heck
81abfdc13d Fix problem noted by Scott in bug #11125.
Need to set the Buffers for math insets, too.
2018-05-08 02:11:49 -04:00
Jean-Marc Lasgouttes
cd9e42dc35 Improve UndoGroupHelper and use it more
Now the helper class contains logic that checks whether buffer are
known before closing them. This avoids potential crashes.

Use it in different places to siplify code. It is not clear at this
point whether it should be used everywhere.

Followup to bug #10847.
2017-12-13 11:10:49 +01:00
Jean-Marc Lasgouttes
8b107f0490 Handle properly undo groups in embedded work areas
When a buffer is in an embedded work area (adv. find&replace), it is
not found by BufferList:::exists(), and therefore the undo group
created in GuiApplication::dispatch and in the handling of
LFUN_COMMAND_SEQUENCE will not be closed.. Crashes can ensue, as
described in Ubuntu bug:
https://bugs.launchpad.net/bugs/1737429

The solution is to introduce BufferList::isInternal and act on it.

Fixes bug #10847.
2017-12-13 10:46:54 +01:00
Jean-Marc Lasgouttes
cc7364dfc5 Better handling of multiple buffers in UndoGroupHelper
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. The solution is to replace buffer_ with a set<Buffer*>.

A use case among others is InsetLabel::updateReferences.
2017-11-29 14:46:15 +01:00
Richard Heck
0bcb9732c5 Rename Paragraph::setBuffer to Paragraph::setInsetBuffers, to avoid
confusion about what this routine does.
2017-10-16 15:48:47 -04:00
Richard Heck
66e1819ad1 Fix the way that the Buffer gets set on undo.
Previously, we went through the entire Buffer and set it for every
single inset. Now we just do it for the insets we pasted.
2017-10-16 15:48:47 -04:00
Jean-Marc Lasgouttes
4eb9b50dc6 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.
2017-07-04 16:34:34 +02:00
Jean-Marc Lasgouttes
82b6dc8aa9 Update all paragraphs layouts when undoing bufferparams
When undo restores a previous BufferParams instance, it should also
update all the layout pointers in the document's paragraphs.

Fixes #9916.
2016-01-20 15:20:51 +01:00
Jean-Marc Lasgouttes
8ec4080537 Remember the cursor before an undo group
With this patch, the cursor position before undo can be saved when
creating an undo group. Any such value will supercede parameters
passed to recordUndo. Only the first such cursor set by nested
beginUndoGoup takes effect.

Fixes bug #9663.
2015-07-21 11:57:50 +02:00
Jean-Marc Lasgouttes
a7896cb190 End all Undo::Private members names with an underscore 2015-07-16 14:48:23 +02:00
Jean-Marc Lasgouttes
7f0ac0932b Avoid crash with undo in a closed collapsable inset
The recipe for reproducing this crash is to do a search and replace
that changes a string present in a collapsed inset, and then undo.

This is a followup to 17e435c4, which used editable() instead of
isActive(); this commit was amended at c2f785bd, since editable() is
not set properly in mathed.

Truth is, editable() is not the right property to test against, since
it is false for a collapsed inset, which does not prevent a cursor
from pointing inside. Therefore sanitize should not change the cursor
in this case.

Hopefuly, this is the last word on the subject. Alternative would be
to drop this if()-clause completely.
2015-05-26 11:19:05 +02:00
Jean-Marc Lasgouttes
7760c5ccf2 Create proper undo groups for advanced find and replace
Create new helper class UndoGroupHelper, which simplifies a lot the
handling of undo groups in cases like this one. The class tracks open
undo buffers and allows to switch buffers transparently.

Using the class for advanced search and replace is trivial. THe class
may be useful in some other classes.

Fixes ticket #8658
2015-05-22 16:42:10 +02:00
Jean-Marc Lasgouttes
32148586a8 Place the cursor correctly after undoing an inset dissolution
The cleanup in 11ca1406 was not correct. It is actually not possible to implement recordUndoInset from the undo API, since the cursor may not be at a different level than the text to be saved.

Fixes ticket #9553
2015-05-20 12:14:34 +02:00
Jean-Marc Lasgouttes
11ca140667 Clean-up the undo API
* Remove the UndoKind parameter in the general interface
* move recordUndoInset to Cursor
* remove one variant of Undo::recordUndo.
* get rid of Text::recUndo.
2015-04-01 14:18:23 +02:00
Jean-Marc Lasgouttes
ed3d9544a3 Improve undo of consecutive insertions/deletions
The old scheme was:
 * multiple insertions are undone by groups of 20
 * multiple deletions are undone in one big block

The new scheme is to stop merging undo elements after 2 seconds of elapsed time.

Moreover, the merging of undo elements stops when the cursor has moved. Potentially, this could allow to remove many of the finishUndo() calls.

Fixes bug #9204.
2015-03-16 18:31:22 +01:00
Jean-Marc Lasgouttes
58b3971eeb Avoid crash with after a params undo.
When doing a non-atomic undo, one should not try to merge with a previous params undo.

This fixes bug #7740.
2015-03-11 16:55:51 +01:00
Jean-Marc Lasgouttes
7021f4c342 Implement new recordUndoBufferParams method.
Rename recordUndoFullDocument to recordUndoFullBuffer.

Separate the notion of recording changes to paragraphs and recording changes in buffer parameters.

Audit every user of recordUndoFullDocument and replace it with either recordUndoBufferParams or recordUndoFullBuffer. Add comments to identify remaining work.
2015-01-22 15:15:21 +01:00
Jean-Marc Lasgouttes
4356f2254a Respect group integrity when removing stuff from the Undo stack.
Fixes: #9079
2014-04-20 19:01:07 +02:00
Jean-Marc Lasgouttes
d25e273abf Whitespace 2014-02-14 12:00:56 +01:00
Richard Heck
d79225ae98 Remove all messages to user related to assertions. We'll just use
a basic message which is defined in lassert.cpp now.
2013-04-27 17:52:55 -04:00
Richard Heck
1b1f8dd235 Audit all the LASSERT calls, and try to do something sensible at
each failure.

There are several places I was not sure what to do. These are marked
by comments beginning "LASSERT:" so they can be found easily. At the
moment, they are at:

Author.cpp:105: // LASSERT: What should we do here?
Author.cpp:121: // LASSERT: What should we do here?
Buffer.cpp:4525:        // LASSERT: Is it safe to continue here, or should we just return?
Cursor.cpp:345:         // LASSERT: Is it safe to continue here, or should we return?
Cursor.cpp:403:         // LASSERT: Is it safe to continue here, or should we return?
Cursor.cpp:1143:                // LASSERT: There have been several bugs around this code, that seem
CursorSlice.cpp:83:     // LASSERT: This should only ever be called from an InsetMath.
CursorSlice.cpp:92:     // LASSERT: This should only ever be called from an InsetMath.
LayoutFile.cpp:303:                     // LASSERT: Why would this fail?
Text.cpp:995:           // LASSERT: Is it safe to continue here?
2013-04-25 17:27:10 -04:00
Jean-Marc Lasgouttes
538570a1e5 Fix bug #8342: Endless undo group messages
Fix thinko in Undo::endUndoGroup.
Do not reset undo groups in Undo::clean

The underlying problem remains: the various VC functions should not
always reload the buffer or at least should use the parameter
clearUndo=false.
2012-09-17 11:24:39 +02:00
Jean-Marc Lasgouttes
f6b1c24b99 Fix bug #5204: Undo removes text selection
This commit does a bit more than fix selection, since it saves the full cursor state
in the undo stack. This means that undo now restores:
* the selection
* the current font
* transient mark (shall we keep this one?), logical position...

In order to do that, it introduces an intermediate class between Cursor and DotIterator: CursorData.
The new inheritance diagram is thus
  DocIteraator -> CursorData -> Cursor

CursorData contains all the members of Cursor that define the current position, but not the stuff
related to current view of dispatch mechanism. It may make sense in the future to move members
between CursorData and Cursor and to move some member functions to CursorData.

Now UndoElement uses CursorData for cur_before and cur_after, but not for the cell. The undo API uses
also CursorData instead of DocIterator.
2012-07-15 18:16:09 +02:00
Jean-Marc Lasgouttes
c22334eb3b Revert "Tentative fix to #8159: Undo doesn't restore environment depth correctly"
This reverts commit e3854bb59b.
2012-06-29 15:22:24 +02:00
Jean-Marc Lasgouttes
bcd6990eca Revert "Revert "Tentative fix to #8159: Undo doesn't restore environment depth correctly""
This is becoming crazy :)

This reverts commit 5b531b56ef.
2012-06-05 12:55:37 +02:00
Jean-Marc Lasgouttes
5b531b56ef Revert "Tentative fix to #8159: Undo doesn't restore environment depth correctly"
This reverts commit e3854bb59b.
2012-06-05 11:32:56 +02:00
Jean-Marc Lasgouttes
e3854bb59b Tentative fix to #8159: Undo doesn't restore environment depth correctly
The undo range is extended to encompass all the paragraph after the end that
are a non-zero depth. The reason is that these paragraphs may see their depth
reduced if the last paragraph sees its depth reduced.

Note that there is a memory cost, since we store paragraphs than may not be
modified in practice. This may matter for some pathological files (people
putting all their document at depth 1 for a weird reason?)

I tried to be careful, but this can introduce new bugs. Please test.
2012-05-22 22:18:34 +02:00
Jean-Marc Lasgouttes
ec3aed75ad Fix bug #6367: Screen jumps around when using undo/redo
http://www.lyx.org/trac/ticket/6367

* Undo.cpp: 
 - rename cur member of UndoElement to cur_before
 - add new member cur_after, which is set by Undo::endUndoGroup
 - create a new Undo::endUndoGroup variant that takes a Cursor as parameter. We cannot get rid of the old one because it is used for LFUN_COMMAND_SEQUENCE.
* Cursor.cpp: 
 - use endUndoGroup(Dociterator const &) for dispatch
 - update Cursor::endUndoGroup to pass cursor.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40713 a592a061-630c-0410-9148-cb99ea01b6c8
2012-02-07 14:56:16 +00:00
Stephan Witt
af77fb5186 #7208 reset undo group level in Undo::clear() too
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37161 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-10 09:44:55 +00:00
Abdelrazak Younes
a07d9f2192 Clear undo/redo stack when reloading buffer. This fixes #7208.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37155 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-09 17:55:16 +00:00
Jean-Marc Lasgouttes
3370b1d2fa Fix the last part of #3733:
- In GuiApplication::dispatch, do not call markDirty() for lfuns that are not ReadOnly
- In Undo::Private::recordUndo, call markDirty(). The indicator of dirtyness is now the existence of an undo element.
- In lyxfind, remove several markDirty calls that are not needed anymore.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36772 a592a061-630c-0410-9148-cb99ea01b6c8
2010-12-08 10:30:45 +00:00
Jean-Marc Lasgouttes
2661b9b22e Some Undo cleanup. Functionality should be unchanged
- whitespace and typos in comments
- make sure that the Undo::recordUndoXXX functions all go through
  Undo::Private::recordUndo


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36771 a592a061-630c-0410-9148-cb99ea01b6c8
2010-12-08 10:04:07 +00:00
Jean-Marc Lasgouttes
574931dcdb Fix bug #6930: no undo for inset type changing
THis is a consequence of the new AtPoint mechanism. In the old
world, recordUndoInset was called before INSET_MODIFY. I reintroduced
manual recordUndoInset calls in all places that matter. I suspect
that this issue should be revisited later.

Note that recordUndoInset can now take an optional parameter that tells
what inset is concerned. This is useful because the cursor can be
either just inside the inset or in front of it.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36580 a592a061-630c-0410-9148-cb99ea01b6c8
2010-11-29 09:47:46 +00:00
Jean-Marc Lasgouttes
3e99283f2b Make sure that the current undo element is finished before marking stacks dirty
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35075 a592a061-630c-0410-9148-cb99ea01b6c8
2010-08-07 10:40:25 +00:00
Jean-Marc Lasgouttes
f8eda52820 Fix bug #3733: 'undo' does not revert 'changed' status for file
* src/LyXAction.cpp: add ReadOnly flag to LFUN_UNDO and LFUN_REDO, since
  we do not want the dispatch mechanism to mark buffer dirty after them.
* src/BufferView.cpp: handle "by hand" the activation of undo/redo
* src/Undo.cpp: add lyx_clean member to UndoElement and make sure to 
  maintain it with undo operations; add a new markDirty() member for UndoStack
* src/Buffer.cpp: when saving a document, mark the undo and redo stacks 
  elements as dirty.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35068 a592a061-630c-0410-9148-cb99ea01b6c8
2010-08-06 23:54:04 +00:00
Richard Heck
5577e877bb Try to move all updateBuffer() calls to a central location. We now use
DispatchResult to store a flag that tells us whether we need a buffer
update or not. 

So: If you find a missing one, go to an appropriate place in the
dispatch and call cur.forceBufferUpdate() or, if you don't have a cursor
but do have a DispatchResult, call dr.forceBufferUpdate().

There is one remaining call I could not move, in
TextMetrics::redoParagraph. But this looks like an emergency call when
the macro context has not been set. There are also a couple calls that
are connected with buffer creation that I commented out, since the same
call is done again almost immediately. But I'm not positive about those.

Now the nice thing would be to do the same for updateMacros().


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34826 a592a061-630c-0410-9148-cb99ea01b6c8
2010-07-09 14:37:00 +00:00
Enrico Forestieri
cf1f59dd4d Fix bug #6678: Crash when undoing backspace inside math-macro
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34370 a592a061-630c-0410-9148-cb99ea01b6c8
2010-05-04 16:16:20 +00:00