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

During editing, live preview and source mode are switched #1

Open
czottmann opened this issue Jan 3, 2024 · 3 comments
Open

During editing, live preview and source mode are switched #1

czottmann opened this issue Jan 3, 2024 · 3 comments

Comments

@czottmann
Copy link

czottmann commented Jan 3, 2024

Hi, first up: thanks for the plugin, it's exactly what I was looking for.

I'm experiencing a bug in v1.0.1 on Obsidian 1.5.3 on macOS. During editing, the plugin renders its checkboxes as live preview when my editor is set to "Source mode", and vice versa.

Steps to reproduce

  1. Set editor to "Live Preview" in settings
  2. Create table and add checkboxes
  3. Checkboxes in tables will be rendered as plain text (while checkboxes outside of tables are rendered as graphical checkboxes).
  4. Set editor to "Source mode" in settings
  5. Checkboxes in tables will be rendered as graphical checkbox text (while checkboxes outside of tables are rendered as plaint text).

Let me know if you need more information or data. I'm a plugin dev myself, I can provide. ;)

@preethamrn
Copy link

+1 to this on desktop. Interestingly, this works fine on Android (latest mobile version is 1.4.16). I'm guessing this regression has something to do with the table view changes in v1.5.3

@preethamrn
Copy link

Did a bit of debugging on my side and seems like in annotateCheckboxes the view iterates through all the nodes properly however in buildDecoration (which is the method that actually adds the checkbox elements), it only gets the first row and then skips to the end of the table.

@preethamrn
Copy link

preethamrn commented Jan 5, 2024

Seems like view.visibleRanges skips over the entire table.

For example,

view.visibleRanges: Array(2)
0: {from: 93, to: 1103}
1: {from: 1686, to: 1800}

93 is the end of the frontmatter. 1103 is the first character of the table, and 1686 is the last character of the table.

So naturally the plugin isn't working because it's not even able to process the nodes within the table. The question is whether this is a bug on the Obsidian side or if there's another way to iterate through the nodes within the table.
Apparently this also happens with callouts which have existed for many versions so I'm guessing there's a workaround to get view plugins to work with this.

One solution would be to update this to iterate over view.viewport instead of view.visibleRanges. However even after making that change I'm still stuck trying to figure out why the decorations aren't working (seems like the CheckboxWidgets are created but the decoration replace isn't running in Live Preview mode).

When I try replacing other elements with CheckboxWidgets (eg. replacing list items) it works perfectly, so I'm guessing there's some limitation with rendering/replacing widgets inside tables.

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

2 participants