PolicyStat / ckeditor-plugin-structured-headings

MIT License
0 stars 1 forks source link

Discover the existing heading preset on document load #67

Closed caffodian closed 7 years ago

caffodian commented 7 years ago

Figure out what the current preset should be, based on the headings already in the document.

Alternately, we could add an extra invisible element that stores the preset, but that seems annoying to everything we've already done.

caffodian commented 7 years ago

However, storing the extra invisible element would allow for presets to more easily change

caffodian commented 7 years ago

idea:

assert all headings of the same level have the same bullet styling class
candidate_presets = copy(all_presets)
for all heading levels:
    for all candidate_presets
          if the candidate preset's bullet doesn't match the current heading level's bullet, remove it from candidates
    if one candidate remains:
         return it

return one of the few remaining candidates (somehow we didn't have enough information to determine which one it should be)
caffodian commented 7 years ago

with the default settings, we should never need to go past the first heading level, since all the first levels differ

caffodian commented 7 years ago

the ultimate worst one would be if all presets only differed on the 5th level

caffodian commented 7 years ago

Ideally this function should be exposed on the plugin, this will make for less bad testing.

caffodian commented 7 years ago

Updating things in place is annoying

caffodian commented 7 years ago

boo @ sketchy set support in IE11 as well

caffodian commented 7 years ago

Something that sucks kinda, is we'll always have 1.1.1.1.1. to fall back on if we can't detect something.

caffodian commented 7 years ago

The default case also sucks because it never gets removed. This is why even on sets where we actually detect correctly, the "return first" idea doesn't wokr

caffodian commented 7 years ago

So after fixing some bad mixups due to my unpolished variable naming, we actually run into the issue I hypothesized above, which is that we shouldn't consider "1.1.1.1.1." as a candidate until all others are exhausted