📜 ⬆️ ⬇️

Everything is not so simple with Ctrl + Z: about undo in fast editing ONLYOFFICE

Randomly nakosyachili in the document that you just fumbled? Drag-n-drove somewhere a piece of someone else's text and do not know how to live on? Did you drop your colleague's cell in the cell and destroy its data? Ctrl + Z more than once saved our lives and reputations of respectable colleagues who do not spoil other people's (and their) documents.

In the last issue, we added the ability to make Undo in quick co-editing. Why it was not there before, how everything is arranged there, and why it happens that you press undo all the way, and the document still does not remain empty, you will learn from this article.



')
Undo in the fast mode of joint editing appeared together with footnotes in version 4.3. You can learn more about the release from our previous article (you will only learn about undo from this article).

Fast, strict, angry


A short reference to the differences between codediting modes:


Fast co-authoring is enabled by default in ONLYOFFICE editors. Previously, it was not undo.

Why earlier in the fast mode was not undo


We thought it was dangerous for the document. Suppose Nikolai inserts an autoshape, and Gennady drags into it a piece of text from a document. Then Nicholas cancels the action, as a result of which the autoshape is deleted. And with it, and part of the text, which is already not to return. Gennady and Nikolai sadly go to drink tea, discussing how to recover the lost text.

Nevertheless, we came to the conclusion that even in fast mode, the ability to cancel the last action is needed. It is just convenient. For example, in the situation described at the beginning of this text, when you, selecting the text for more attentive reading, accidentally dragged it with a mouse, while at that time someone else edited the document. Or did not even edit, but simply forgot to close it. Or you yourself forgot to close the same document in the next tab. In general, the need is possible to automatically roll back the last action.

Undo, of course, must be treated with caution (but in fact, you run the risk of just fumbling for someone with an editable document). But we will tell you how everything works to minimize the risks.

Google and we


We are constantly asked (actually asked): Did you do this like Google Docs? Not.

Yes, they have joint editing and the ability to do undo, and we also have these things. But this does not mean that everything inside us is the same.

Like Google . The document is on the server, all edits are sent there, and the final version of the document is being compiled there. For example: Nikolai singled out some word in bold , and Gennady in italics . Both two send their changes to the server, which is already resolving this embarrassment: in particular, tells Nicholas to add italics , and Gennady to make his italics bold . In such a scheme, a situation in which the same document looks on different clients differently is possible (for a very short period of time, of course).

Like ONLYOFFICE . If Google’s document core is edited on the server, then we have it all happening on every client. The server is used as a database in which changes are stored. How should such a scheme change the situation when Nikolai singled out some word in bold and Gennady in italics? The changes will be consistent, with the sequence being the same on each client. The situation in which Nikolay and Gennady have documents look different at some point in time is impossible.

How is this generally related to undo, you ask (in fact, we have no idea whether you ask or not, but imagine as if you asked). From the next point in our story you will understand how.

What happens when you press Ctrl + Z


As we have said, in ONLYOFFICE all the most important things happen directly on the client. There is also a list of actions - not only their own, but also others. Your own actions are flagged so that you can roll back later.

And here we come to how undo actually happens. When a person edits a document in solitude everything, in principle, is understandable. The block of changes stores the actions of one person and, if necessary, we simply take the last action and produce an anti-action. The block of actions is reduced by one.

In collaborative editing, the scheme is more complicated simply because the actions of several people are stored in the list of changes.

Consider a simple example. The document contains the following text:

a B C

Nikolay added the letter d at the end and received the text:

abvd

Seeing the result, Nikolai changed his mind and wanted to cancel the input of the letter D. At the same time, picky Gennady deleted the letter b and the following text remained in the document:

avd

Nikolai presses undo. Deletion and addition of text occurs by position. With his first action, Nikolay added a letter to position 3. In normal editing, undo would work simply as deleting a letter from the third position. But Gennady has already tried and removed the letter b from position 2 and the letter d has moved to its place. Thus, in the third position, it is now just empty and there is absolutely nothing to remove from there.

This means that the simple scheme does not roll, and before canceling Nicholas's actions, you need to overtake them at the very end of the block, as if they were the last (after all other people's actions).

If you transfer the action of Nikolai to add the letter d to the very end of the block, that is, after Gennady villainally removed the letter b from the second position, it turns out that Nikolai added the letter D to position 2. Do the opposite: removing from position 2. Undo passes

Thus, the basic principle is as follows: we take a pack of actions of the client who wants to undo, we switch them (we stop through someone else's actions according to certain rules) and form a new block of reverse actions, as in the usual undo.

The client of Nicholas, who has done undo, has an anti-action, and the rest is sent just a bundle of his actions, that is, for them there is no difference whether he made undo or simply deleted the letter with his hands.

With undo, of course, various interesting problems, for example

Unrolled action


Another simple example:

1. Nikolai adds text 12.
2. Gennady removes 2.
3. Nikolai does undo 2 times.
4. Gennady does undo.



So, both users rolled back all their actions and both did not have a single undo in their sleeve. However, the initially empty document did not remain empty after canceling all actions performed in it. The number 2 proudly flaunts in it. It is impossible to roll it back with the help of undo.

Vanishing elements


Consider again the case of Gennady and Niklai at the beginning of the article:

1. Nikolai adds an autoshape.
2. Gennady typing text in the autoshape.
3. Unstable Nicholas makes undo autoshapes.
4. Along with the autofigure, the text typed by Gennady inside it also disappears. Finally.

Any problem with undo in fast joint editing is due to the fact that the sequence of real actions in the document and the sequence in which undo is pressed are not the same.

These are not the drawbacks of our implementation of undo. It works correctly. It will be ideal if you and your colleagues work on different objects at the same time. And here is our parting word for you: be, as it is now fashionable to say, mindful, working with documents. Switch between co-editing modes and use wisely undo.

Source: https://habr.com/ru/post/327454/


All Articles