Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide markdown syntax as cursor leaves the position? #68

Open
erikvlm opened this issue Aug 24, 2022 · 4 comments
Open

Hide markdown syntax as cursor leaves the position? #68

erikvlm opened this issue Aug 24, 2022 · 4 comments

Comments

@erikvlm
Copy link

erikvlm commented Aug 24, 2022

Is it possible to have the markdown syntax hide as the cursor leaves the text? Sort of like Obsidian does in their live preview mode?

Eg writing **bold** to only show bold? (Notice that the asterisks have been "hidden")

@DivineDominion
Copy link
Collaborator

It's technically possible by using NSGlyphGenerator to replace the glyphs for * with none (e.g. unless selected)

The more convenient way to change the behavior is to use a delegate instead of overriding the glyph generator (which doesn't even work on iOS): NSLayoutManagerDelegate.layoutManager(_:shouldGenerateGlyphs:properties:characterIndexes:font:forGlyphRange:)

Example https://stackoverflow.com/a/57697139/1460929

@erikmalmberg
Copy link

I tried following that stackoverflow post but couldn't get it to work - can you show a crude example of how you would?

@DivineDominion
Copy link
Collaborator

Sorry, no, just notes.

There's a WWDC session: Dan Schimpf and Aki Inoue (2010): Advanced Cocoa Text Tips and Tricks.

PDF version e.g. available here:
https://docs.huihoo.com/apple/wwdc/2010/session_114__advanced_cocoa_text_tips__tricks.pdf

I'd suggest trying that on macOS, first, because iOS didn't have the API back then. NSLayoutManagerDelegate then will be the way forward IIRC.

@ruddfawcett
Copy link
Owner

This would be great functionality. Unfortunately it is something that I am unable to get to: @DivineDominion's suggestions are good ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants