[NestedListHelper] Fix indentation of selection, add tests
ClosedPublic

Authored by poboiko on Apr 26 2020, 5:48 PM.

Details

Summary

When we try to increase / decrease an indentation level of a selection, just change
indentation level of each block in the selection, and then make sure all styles
are consistent via reformatList.

This actually fixes indentation of selection: previously all blocks had the same indentation after this action.

Add a unit test that covers as much weird selections & indentation cases as I could imagine.

Slightly overlaps with D29208: [NestedListHelper] Improve indentation code, so this one should be applied after that.

Test Plan

make && ctest

Diff Detail

Repository
R310 KTextWidgets
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
poboiko requested review of this revision.Apr 26 2020, 5:48 PM
poboiko created this revision.
dfaure added inline comments.Apr 26 2020, 10:57 PM
src/widgets/nestedlisthelper.cpp
225

should the opposite happen? delete the list when decreasing indentation?

Or is that what the blkFmt.setObjectIndex(-1); is about?
A comment there would be useful...

To me setObjectIndex(-1) sounds like it could kill any kind of embedded object there.... but I might be wrong.

poboiko updated this revision to Diff 81585.Apr 30 2020, 2:04 PM

Make the code that removes the block from the list more obvious (without setObjectIndex magic)

poboiko added inline comments.Apr 30 2020, 2:04 PM
src/widgets/nestedlisthelper.cpp
225

We indeed delete it when decreasing, but here delta > 0, which corresponds to increasing :)

Regarding setObjectIndex(): it does indeed look like magic, and I don't totally understand it either. It was there, however, and it is also present in the official Qt TextEdit example, where it's used when item is removed from the list.
I've found more explicit way: just remove the block from list and set it's indentation to zero, it seems to be working well.

dfaure accepted this revision.May 2 2020, 2:03 PM
This revision is now accepted and ready to land.May 2 2020, 2:03 PM
This revision was automatically updated to reflect the committed changes.
Restricted Application added a project: Frameworks. · View Herald TranscriptMay 2 2020, 8:37 PM