Editor model: fix race between editing and notification-after-saving.
ClosedPublic

Authored by dfaure on Nov 21 2016, 11:20 PM.

Details

Summary

Don't replace text being edited by the user with older text coming
from akonadi notifications. This means tracking whether the editor
has focus or not, since we still want it to react to the notification
that the title has changed when renaming an item in the central list.

This fixes the cursor jumping back to position 0 while editing,
and the occasional loss of characters.

This change also allows to get rid of the libical whitespace workaround.
Now the libical issue is only visible when leaving a trailing whitespace,
switching tasks and back, and the whitespace is gone => no big deal.

Test Plan

The related feature tests I added recently still pass.
Editing in zanshin doesn't exhibit the race anymore.

Diff Detail

Repository
R4 Zanshin
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
dfaure updated this revision to Diff 8363.Nov 21 2016, 11:20 PM
dfaure retitled this revision from to Editor model: fix race between editing and notification-after-saving..
dfaure updated this object.
dfaure edited the test plan for this revision. (Show Details)
dfaure added a reviewer: ervin.
dfaure added a subscriber: Zanshin.
ervin set the repository for this revision to R4 Zanshin.Nov 23 2016, 8:56 AM
ervin requested changes to this revision.Nov 23 2016, 6:34 PM
ervin edited edge metadata.

Also needs new unit tests for EditorView and EditorModel to check the behavior changes there. Currently only new acceptance tests got provided.

src/presentation/artifacteditormodel.cpp
224

Remove curly braces

230

Ditto.

src/presentation/artifacteditormodel.h
116–117

applyNewText + applyNewTitle ?

This revision now requires changes to proceed.Nov 23 2016, 6:34 PM
dfaure updated this revision to Diff 8457.Nov 23 2016, 10:08 PM
dfaure edited edge metadata.

Coding style and renamings, but also applying the same logic to all widgets for consistency.

After all the same race could happen while playing with one of the date widgets for instance.

Unit tests are good at pointing out inconsistencies ;-)

dfaure added inline comments.Nov 23 2016, 10:25 PM
tests/units/widgets/editorviewtest.cpp
404

BTW I would expect that such a test would say

QCOMPARE(textEdit->toPlainText(), QStringLiteral("New title"));

rather than using model.property() without really knowing what's going to come out of it.
(e.g. if the change didn't happen in the model, this would still pass).

But I guess you consider the stub model to work, as it's part of this unittest, i.e. not the thing we're actually testing here. Still, a wrong value for shouldReactToNotifications and this would still pass, with a wrong expected value...

In general I prefer expected values to be constants than values returned by methods, for this reason.

ervin added inline comments.Nov 24 2016, 7:00 AM
tests/units/widgets/editorviewtest.cpp
404

That's indeed correct. I think we did that at several places, we kind of assume the stub is "perfect" to avoid repeating ourselves on the data. Still that's somewhat dangerous we should probably use const variables used both in the GIVEN and the THEN.

ervin requested changes to this revision.Nov 24 2016, 7:05 AM
ervin edited edge metadata.

Almost there, still misses the tests for ArtifactEditorModel though.

This revision now requires changes to proceed.Nov 24 2016, 7:05 AM
dfaure added inline comments.Nov 24 2016, 8:09 AM
tests/units/presentation/artifacteditormodeltest.cpp
250

Hmm? This looks like a unittest for artifacteditormodel to me.

ervin accepted this revision.Nov 24 2016, 9:10 AM
ervin edited edge metadata.
ervin added inline comments.
tests/units/presentation/artifacteditormodeltest.cpp
250

Pff, I wonder how I missed it...

This revision is now accepted and ready to land.Nov 24 2016, 9:10 AM
This revision was automatically updated to reflect the committed changes.