esm7/obsidian-rtl

Table support in Obsidian 1.5.4

Closed this issue · 5 comments

esm7 commented

In Obsidian 1.5.4 (not yet released), they fixed the behavior of tables when in RTL mode. Naturally, the native behavior only works for the native RTL support which means the entire editor is RTL, and obsidian-rtl should expand upon that.
It seems like per-cell text direction is not going to work very well as it leads to erratic cursor movements and may be unnatural for users. So at the very least, I think that setting the direction of the whole table in 'auto' mode according to the direction of the first table cell, will produce a good result.

I'm almost able to achieve this behavior using pure CSS:

.cm-table-widget:has(thead tr:first-of-type th:first-of-type .table-cell-wrapper.esm-rtl) {
	direction: rtl;
}

(Reading View will need a separate rule but that seems easy)

There's just one problem though: it seems like the editor extension (AutoDirPlugin) doesn't correctly update the esm-rtl and esm-ltr classes on the fly.
From initial debugging, seems like when editing a table cell, an "internal" editor is created for that cell, and that editor launches updateEx calls for that cell. However, seems like it doesn't properly update the document "above" when the cell finishes editing.
When opening a note for the first time it works great, so seems like the problem boils down to understanding the editor update and correctly locating it, and not with the low-level logic.
@zoli, any chance you may be able to give this a look? Even if you don't have Obsidian 1.5.4 yet and can't test the full RTL support, just finding the way to correctly update the classes upon table changes in any Obsidian 1.5.x would be a huge help 🙏

zoli commented

Sure, I will look into this soon.

zoli commented

OK, Finally I had time to look into this. You are right adding the style you mentioned will fix the view except for the moving between cells and some update problems. Update problems seem resolvable, but I don't know if Obsidian has given access to changing cell movement behavior for plugins.

esm7 commented

Actually there seems to be some bizarre behavior around the cursor movement (even when not mixed LTR-RTL) because of how the parent element has direction: rtl and the table wrapper having direction: ltr. I'll see if I can improve upon that.

zoli commented

There is another option to use other CSS rules to force table render on right side (like float: right) But using other rules can cause other proplems.

zoli commented

Obsidian looks to table direction on executing movement commands, If they just also consider the table cell or first parent of the cell that has direction would solve everything.