3 | | 1. Open plugins/widget/dev/nestedwidgets.html |
4 | | 2. Click image2 (nested within simplebox). |
5 | | 3. See format drop-down. |
| 5 | All these behaviours come from a decision we made while working on widget system. We decided that styles will be applicable to block widgets, because they may contain nested editables in which these styles may be applicable, even if they are not applicable to the widget itself (and besides widget styles they never are). This reasoning definitely makes sense - if I have 3 nested editables inside a widget and I want to make all text inside them bold I can focus widget and apply bold. Alternatively, I would have to apply bold three times. To make all this work we needed to modify style system so it traverse non-editable fragments of content, finds nested editables, retrieves their filter instances and asks them whether styles is allowed inside. This part works great. |
| 6 | |
| 7 | Unfortunately, all the rest is a mess. Problems are caused by inability to correctly set style's command state and value. See the following scenarios. |
| 8 | |
| 9 | 1. Focus captioned image2 and apply bold. Bold is applied in the caption. Now, try to remove the bold. You can't, because bold button is still off after applying bold. Why is it off? Because `<figure>` is not inside a `<strong>`. Are we able to set the state to on? I don't think so - this would mean traversing focused widget's DOM, finding nested editables and then what? Enabling style if it's applied to entire content of all nested editables? Or at the beginning of any editable? In any case this would be a performance killer, because we not only need to find editables, but also first editable place inside them (text node, image, space before `<br>`, widget, etc). |
| 10 | 2. Imagine the above scenario with captioned image2 nested in simple box. The algorithm will need to go inside that image2 when simple box is selected. |
| 11 | 3. What is the expected format drop-down's value when simplebox is focused and it its content there are headings and paragraphs? Simplebox has a header in which format should be disabled. Then it has content, which may start with a normal block (paragraph, heading) or for example a captioned image. Image does not allow changing format (so should drop-down be disabled?), but after image there may be paragraphs, so maybe format should be enabled (but then what with the value?). |
| 12 | 4. Imagine all these scenarios with widgets containing multiple nested editables of different types. User will never intuitively know what will happen and what's just happened. |
| 13 | |
| 14 | And I'm sure that there are move lovely cases like these. |
| 15 | |
| 16 | Therefore, I don't see other option than disabling styles when block widget is focused. Only widgets styles should be active. |
| 17 | |
| 18 | Note that this won't change the behaviour of applying style to a selection containing some content outside a widget and a widget (e.g. bolding after doing `CTRL+A` on text with captioned images). Style will still be applied to all places in which it's allowed. There's a substantial difference between these cases - the start of selection. When selection does not contain only a widget, it starts in an editable place, so we can check style's state in that place. |