Line-wrapping/Readable line length table "compatibility"

I really like editing with line-wrapping and readable line length as it makes it easier to read the documents. However, lately I have been using tables a lot in some of the documents I’ve been editing and the markdown for a table quickly outgrows the width of readable line length, and even line-wrapping when using full screen. This makes the tables extremely hard to read and edit as table rows will end up spanning multiple editor rows.

I don’t have a perfect solution in mind but I do have a suggestion, which would be to simply let tables (only) not line-wrap and flow out of the readable line length and then adding a horizontal scroll-bar to the table.

I know this could be a plugin instead but it just seem like such a necessary addition to be able to edit tables with line-wrapping that it really feels like it should be an editor feature.

Hi @Magnus ,

Thanks for the suggestion.
Yeah, that’s one of the biggest frictions for a plain-text Markdown editor.
You are right, and I considered the possibility of partially disabling line-wrapping, too.
The problem is that CodeMirror allows line-based text styling. It requires to replace a multi-line block with an embedded separate CodeMirror instance, which would be something for WSYISWG-style features.

I found a workaround to partially disable line-wrapping with CSS.
It cancels the line-wrapping styles for .cm-line.md-table:

.cm-editor .cm-content.cm-lineWrapping {
  min-width: 0;
}
.cm-editor .cm-line.md-table {
  white-space: pre !important;
  word-break: normal !important;
  overflow-wrap: normal !important;
  width: max-content;
  min-width: 100%;
  box-sizing: border-box;
}

Result:

It scrolls the entire viewport instead of the table blocks, but I think it’s fine as a plain-text editor.
However, I think there would be a few quirks to fix, so we should carefully test it.
For example, the text selection layer is broken when selecting multiple lines.

I also found a few bugs in the editor decorations during the exploration.

Hi @Magnus ,

I’ve added a new option for disabling line-wrapping for tables and code blocks. Can you try it?

Works as advertised!
It’s still a bit awkward to scroll everything else out of view if the table is really wide but this is for sure usable and good enough for my use-case so I’m happy.

I have however noticed a few things, which I assume isn’t related but I just happen to notice after looking at this.

  • Tables with inline code blocks can’t align because the visual wrapper around the code block doesn’t fit the fixed width font, just like in your example photo. Not a big deal but I does look a bit weird
  • Bullet list items that wrap multiple lines seem to visually start un-indented for the wrapped lines when opening then note and then after a short delay the indentation appears
  • Horizontal scrolling sometimes works, sometimes doesn’t, with my logitech mx master. I don’t know if this is also an issue with other horizontal scrolling input devices

Do you want me to open bug report(s) for any of these?

Cool!
The next idea to try is to add a floating button for toggling line-unwrapping like the copy button on the codeblocks. Wdyt?

Thanks for the feedback.

  1. Tables with inline code blocks can’t align

Yes, it looks weird for sure. It’d be nice to change the style for tables.

  1. Bullet list items that wrap multiple lines seem to visually start un-indented for the wrapped lines

This is a limitation in CodeMirror for performance reason. Extensions process these style tweaks asynchronously.

  1. Horizontal scrolling sometimes works, sometimes doesn’t, with my logitech mx master

Hmm, weird. I use the same mouse (old one) but have no issue so far.
If you find a reproduction step, can you create a topic about it?

Adding the following style override to styles.css should solve the issue #1:

.md-table .md-inline-code {
  padding-inline: 0;
  border: none;
  outline: var(--md-inline-code-border-width, var(--md-codeblock-border-width))
    solid var(--md-inline-code-border-color, var(--md-codeblock-border-color));
}

It has been officially supported as two options:

  • Prose Only keeps code blocks and tables on one line each, so long table rows don’t wrap across multiple lines. It replaces the experimental unwrapBlocks option from v6.1.5, which no longer works.
  • Unwrap at Cursor wraps everything except the code block or table under the cursor. The block un-wraps when the cursor enters it and wraps again when the cursor leaves, and the cursor’s line stays in place on screen.

Also, the style issue has been fixed.
Thanks again for the feedback, @Magnus !

Sorry I never got back to you, but this new implementation is awesome thank you so much!

I unfortunately have not been able to find reproduction steps for the MX Master, but if it helps anything my mouse is a V3 and so far I have observed the issues on Windows so it might just be a Windows window management thing

I can comment on this one. This is a quite old problem with the logitech drivers (on windows) for chromium based apps. There are some quite old issues for VS Code and Electron that talk about this issue.

So there is nothing really that can be done about it.

Thanks for sharing the info, @Lukas !