javalent / dice-roller

Inline dice rolling for Obsidian.md
274 stars 28 forks source link

šŸž Not being in the active line fails to activate Graphical Dice #359

Open 3hree6ixty5ive opened 4 days ago

3hree6ixty5ive commented 4 days ago

Check for existing bug reports before submitting.

Expected Behavior

With rendering of graphical dice enabled, (either with "Always Render Dice", or the |render flag), clicking on a formula while the cursor is on a different line, should result in a graphical dice being rolled, and the result appearing after the dice is done rolling.

Current behaviour

If you click on a formula while the cursor is on a different line the following happens:

  1. The cursor jumps to the line with the formula
  2. The formula flickers briefly and instantly rolls a result
  3. No graphical dice is rolled, however on iOS it briefly appears on screen before disappearing almost instantly.

Subsequent clicks, after the cursor has jumped to the same line, perform correctly, showing a graphical dice and waiting for the result. Moving the cursor to a different line will cause the same issue to occur again.

Reproduction

  1. Launch obsidian sandbox
  2. Install dice roller plugin
  3. Go to "Dice Rollers" in settings and enable "Always Render Dice" (Error also appears when using manual |render flag)
  4. Create a new note
  5. Add a dice formula, such as dice:1d12
  6. Add several new lines with random text
  7. Keeping cursor somewhere in random text, click on formula to roll dice
  8. First click should have error, result will roll instantly with no graphics
  9. Move cursor away from formula to a different line and repeat to see error multiple times

Which Operating Systems are you using?

Obsidian Version Check

1.7.7 and 1.6.5(Installer)

Plugin Version

11.4.1

Confirmation

Possible solution

No response

valentine195 commented 4 days ago

Is this in live preview?

3hree6ixty5ive commented 4 days ago

Yes this is using live preview mode, doesn't have the issue when i switch to Reading mode

3hree6ixty5ive commented 4 days ago

Update: I was able to come up with a fix for Windows using the following CSS:

.dice-roller { user-select: none; }

This stops the first click from moving the cursor and that seems to allow the dice time to roll without glitching, so it works as intended. However this doesn't seem to work on iOS, I'm assuming due to different methods of handling clicks.