Comment 2 for bug 1513933

Revision history for this message
Tim Peeters (tpeeters) wrote :

When the model is changed, some times the selectedIndex is no longer valid (too large) and must be changed.

However, the Sections does not know how the model was changed. Perhaps the model changed from ["one", "two", "three", "four"] to ["one", "two", "three"], with selectedIndex = 1 ("two"). It makes sense then that after changing the model, "two" is still selected. Since the app will know how/why the model changed, I think it is best for the app to set the new selectedIndex when the model changes.

To prevent a selectedIndex >= model.length, we can reset selectedIndex to, for example, 0 or -1 when the model changes. However, when setting the value to >=0, that will trigger the action (if any) associated with that index, which may be unwanted. The only way to prevent this is to always reset the selectedIndex to -1. In that case, no action is triggered, and the app may set sectionIndex to any desired value (which, in turn, will trigger an associated Action if there is one).

I attached an MR that does what I describe above. And it does this *only* if the model is changed after the Sections component was completed to prevent overriding a selectedIndex that was set by the app developer (which would cause a regression of this fix https://bugs.launchpad.net/ubuntu/+source/ubuntu-ui-toolkit/+bug/1511839 ).