I tried the visible overflow for a while, but it doesn’t look neat. I ended up going back to overflow-x: scroll, like in my previous post. What I forgot to mention is I also use Hider plugin with “Hide scroll bars” turned on, to get rid of the scrollbars-in-the-code weirdness. This is the snippet I came up with, works for Live Preview mode:
When you add a wide code block Obsidian wraps the content to match the line length when “Readable Line Length” is activated.
This makes it hard to read the code.
A nicer way would be to provide a scroll bar underneath the code block and let it keep its full width.
This is also needed with obsidian-krokit, which uses codeblocks to render text-like instructions to graphics. The images produced are too wide when readable line width is chosen with the default theme. Scrollbars are not displayed, so the rest of the rendering is never visible.
The ‘minimal’ theme does more of a usable thing, but it still looks a little wonky. Specifically, the image begins from where the text begins, but then expands beyond to the right. Scrollbars also appear. There appears to be something creating sufficient whitespace / padding on the left side to align with the text, but not on the right.
That said, it would probably be better if the default theme did not try to do any fomatting in the form of word wrapping, resizing, etc of the the contents of codeblocks, and displays them as rendered with scrollbars when needed.
I’m not presently touching any CSS, nor have I tried to look for how I can inspect it. This is just the builtin Light theme and the Minimal theme plugin in Light mode being used with obsidian-krokit, with Readable Line Lengths enabled.
Let me add here a quick note.
This is a much harder problem that it seems because there is only one real editor view. There are two options right now:
It’s either as it is now. Codeblock flow and are editable with rest of the text.
Use the same trick used for Tables (use reader rendering while not editing)
Specifically, codeblocks look like in reader (and you can have code wrap, horizontal scroll, prismjs highlight) but the moment you click anywhere to edit them they are “unpacked” to what you see now (with codemirror highlighting, no horizontal scroll, no code wrap).
We picked 1 over 2 because for codeblocks the gain you get is not worth the jarring effect.
It is understandably a technical challenge. I just really hope the team and community plans on looking into it long term . I just use the following hacks from this thread. Makes experience usable for me.
Seconding that this would be wildly helpful! I’m using a css snippet for something like this for now, but it’d be awesome for that to be a first-class citizen. Thanks!
Thanks and just FYI to anyone else reading, I tried this as a snippet and it’s working for me too. The code goes over the boundary of the grey code block, but it works well to disable to code wrapping.
The cursor was getting lost when editing long lines with my previous snippet, so I added :not(.cm-active) to it. Does not seem jarring to me. Works well in both Source Mode and Live Preview. (Remember to use Hider plugin with “Hide scroll bars” enabled.)
Currently Code blocks show the code in a wrapped text format, which makes it harder for codes having long lines/comments to read.
Proposed solution
It would be great to have an option for wrap text/scrollbar so that longer codes can be easily read. Also an option to keep the editor width using would be great.
Related feature requests
Allow better rendering of codeblocks inside indented lists. The code formatting of fences breaks when codeblocks are added at an indentation in lists.