ozntel / oz-image-in-editor-obsidian

This Obsidian plugin to view Images, Transclusions, iFrames and PDF Files within the Editor without a necessity to switch to Preview.
339 stars 13 forks source link

The same image in adjacent panes #30

Closed zsviczian closed 3 years ago

zsviczian commented 3 years ago

Hi Ozan! If I have two documents open parallel, which both include the same image, the image will only show in the pane that was opened first.

image

ozntel commented 3 years ago

Hi @zsviczian, it is because of the additional check we added to prevent image blinking here:

https://github.com/ozntel/oz-image-in-editor-obsidian/blob/cce08c7749a411e9d00621e0b159cd54ce286510/src/check-line.ts#L139

It basically checks each time if the drawing you are adding has the same mtime and alt and if this image is already on the screen. If so, it won't refresh the image to increase comfort by preventing the blinking issue. Since you are trying to view the same image a second time in a different place, this check takes place and the second drawing is not included as a widget, as well. I assume if you change the alt text in the second image, it will be visible.

If I remove this check, each small change will trigger a new image load and decrease the comfort drastically.

Can you maybe write an alternative function to createPNG, which returns png object and additionally mtime of the original excalidraw drawing? I don't know if I can succeed but I can try to use this information and not add into data-attribute of widget anymore

ozntel commented 3 years ago

Can you maybe write an alternative function to createPNG, which returns png object and additionally mtime of the original excalidraw drawing? I don't know if I can succeed but I can try to use this information and not add into data-attribute of widget anymore

I just gave a though and I suppose it won't help, either. The best way to prevent blinking would be creating real png file under the same folder, where excalidraw drawing is located. As long as drawing doesn't change, the png file also wouldn't change. Since for the local png file we would have the same link always, there wouldn't be a blinking issue.

Right now, each refresh creates a new URL for the image, which forces DOM to render the image again. Maybe you have some other idea?

zsviczian commented 3 years ago

How would you like the mtime of the excalidraw drawing to be returned? return {img: Blob, mtime: Date};

On Sun, 13 Jun 2021 at 11:26, Ozan Tellioglu @.***> wrote:

Hi @zsviczian https://github.com/zsviczian, it is because of the additional check we added to prevent image blinking here:

https://github.com/ozntel/oz-image-in-editor-obsidian/blob/cce08c7749a411e9d00621e0b159cd54ce286510/src/check-line.ts#L139

It basically checks each time if the drawing you are adding has the same mtime and alt and if this image is already on the screen. If so, it won't refresh the image to increase comfort by preventing the blinking issue. Since you are trying to view the same image a second time in a different place, this check takes place and the second drawing is not included as a widget, as well. I assume if you change the alt text in the second image, it will be visible.

If I remove this check, each small change will trigger a new image load and decrease the comfort drastically.

Can you maybe write an alternative function to createPNG, which returns png object and additionally mtime of the original excalidraw drawing? I don't know if I can succeed but I can try to use this information and not add into data-attribute of widget anymore

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ozntel/oz-image-in-editor-obsidian/issues/30#issuecomment-860180821, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADNRO6UT2P2CPYYQILVX533TSR2UFANCNFSM46TOCOTQ .

ozntel commented 3 years ago

Hi @zsviczian, it took me a while but I suppose I found a solution, which eliminates the issue you mentioned, and solves the blinking issue at the same time. Can you maybe try to use the plugin with the main.js attached here and let me know if it gives the result you expected?

oz-image-in-editor-obsidian.zip

Basically, I found a way to check the currently loaded blop vs new blop generated by your plugin. Each change in the line checks if blop or alt text changed. If so, it refreshes the image URL and the alt text

ozntel commented 3 years ago

I just released a new update with some corrections for drawings. Please let me know if the issue still persists.