mgmeyers / obsidian-contextual-typography

GNU General Public License v3.0
163 stars 9 forks source link

Add support for edit mode #4

Closed nothingislost closed 3 years ago

nothingislost commented 3 years ago

Here's my take on enabling Contextual Typography in edit mode. This should replicate the preview functionality almost exactly. The following data attributes are automatically added to parent elements:

This makes use of the CodeMirror "renderLine" event and from my testing so far, seems to be pretty efficient.

It should be fairly easy to add support for additional HTML elements. We just need to pick out the appropriate CM tokens and add them to the switch statement.

nothingislost commented 3 years ago

This implementation is problematic in scenarios where cm.refresh() is being called often. For example, when resizing the window, all of the attributes are removed and re-added repeatedly. If you create a style that relies on the data attributes, you will see that style flicker on an off while resizing.

I'm thinking through a more effective way to apply the attributes but open to any suggestions.

nothingislost commented 3 years ago

Closing this as there hasn't seemed to be much interest. I'll add it as a feature in CodeMirror Options.

mgmeyers commented 3 years ago

@nothingislost Apologies, this PR totally fell off my radar as things got busy at school. I'd be happy to take a look, but if you'd like more control over the pacing of development, adding it to your plugin may be the way to go.