javalent / dice-roller

Inline dice rolling for Obsidian.md
272 stars 29 forks source link

Edit mode results different from Read mode results #294

Closed robertdaleg closed 1 week ago

robertdaleg commented 7 months ago

Check for existing bug reports before submitting.

Expected Behavior

In a document, when I add a formula like dice: 2d20 and see a result of "2d20 -> [3, 15] -> 18", and then toggle the editor to read only mode, the results should remain the same.

Also, when logging results to the dice tray, that logging should happen when the editor is in edit mode.

Current behaviour

When I put in a formula in a document, like dice 1d20 and then toggle between read-only and live preview edit modes, I get different results. The results stay the same (every time I enter read mode, I see "2d20 -> [4, 17] => 21", and every time I toggle to edit mode, it displays a different result, but that result doesn't change if I toggle to read mode and back to edit, so it always shows "2d20 -> [12, 1] -> 13" until I click the dice icon to reroll. It's like there is a separate result for live preview edit mode and read only mode.

When I log the results to the dice tray, it only logs when I click the icon in Read mode, but those logged results do agree with what I see in the document. When in edit mode, rolls don't get logged at all, and they're a distinct result from the Read mode results.

Reproduction

To reproduce, start a new vault, add the Dice Roller plugin, turn on the Dice Display "Display Formula with Results" and "Display Dice Button with Results" options. Turn on the Dice Rollers section's "Log Rolls to Dice Tray" option.

  1. In a note, add a formula dice: 2d20 and click on the dice button. Note the dice tray does not log the result.
  2. Toggle the editor to read only mode, note the results (if any at this point) are different from edit mode.
  3. Click on the dice button, see the logged results are the same.
  4. Toggle back to edit mode and observe that the results are what they were the last time you were in edit mode, and not what they show in the dice tray log.
  5. Toggle back to read-only mode, see the results now match to the dice tray.

Which Operating Systems are you using?

Obsidian Version Check

1.5.3

Plugin Version

10.4.4

Confirmation

Possible solution

No response

Zeliret commented 7 months ago

I have the same, same steps to reproduce, just installed the plugin and discovered the issue.

CHINCB commented 7 months ago

I am having the same issue, is there a workaround in the meantime?

valentine195 commented 1 week ago

This is because live preview and read mode go through two different render paths. This cannot be fixed, sorry.