visual-space / visual-editor

Rich text editor for Flutter based on Delta format (Quill fork)
MIT License
290 stars 46 forks source link

Blocks - Code block color coding for multiple languages #18

Closed adrian-moisa closed 9 months ago

adrian-moisa commented 2 years ago

The current implementation of code blocks in Flutter Quill is rather rudimentar. Not much effort was put into this feature so far. We want to develop this feature to render interactive coding tutorials in Visual Space.

Color coding could be done by borrowing the tokens from another open source code editor and applying styling to the lines of text in the renderer without changing the deltas. There are some code editors from where we can borrow the list of tokens. So far I haven't researched a lot the topic. But I imagine a simple and naive implementation would search for language tokens and would apply color coding over them.

Currently the delta format can apply styling over code snippets. The idea itself is rather goofy. Except the benefit of being able to render markers, highlights and attachments using the same logic I'm seeing few reasons why we would allow full formatting in the code. For example now it is possible to add inline code snippet in a code block. Which makes no sense.

image

At the moment we would be happy with a basic code editor that provides color highlighting. But in the future we plan to add some more basic code editing features such as: syntax error highlighter or jump to token. This is by far not an easy job and I'm not even sure how far we want to go with the inline code or if this could be better done in a custom embed. I'm still thinking if the user interactions make sense.

For example I don't know for sure if selecting part of text and part of a code block should be possible. It's almost like being able to select part of text and part of an image and copy pasting them somewhere else.

Edit

@kthecoder has suggested the possibility of using Microsoft's LSP Protocol to implement autocomplete features. I believe this is somewhat beyond what a text text editor should be doing. Using a library for code editing could be a smarter move, since it's someone else's problem. Someone who specialises in code editing. However at the moment these code editors are mostly abandoned and far from complete. Ex: code_editor

Edit 2

Looks like the authors of this super popular extension for Google Docs are happy with this setup. It appears they don't have access from Google to run automatic color coding at runtime. So therefore they apply styles over the existing text via a wizard that has to be manually triggered. This is insane. No way we are doing this.

image

Edit 3 - Some questions to consider

Based on the questions listed above we can conclude we want to have Visual Editor in charge of rendering code blocks. We will disable rich text formatting on the code snippets and leave only code related features (highlights, markers, etc)

Join on discord to get advice and help or follow us on YouTube Visual Coding to learn more about the architecture of Visual Editor and other Flutter apps.