tecosaur / LaTeX-Utilities

An add-on to LaTeX Workshop that provides some features that go beyond the bare essentials
MIT License
474 stars 28 forks source link

Formatted paste copy image path instead of template #383

Closed quentgoutaland closed 1 year ago

quentgoutaland commented 1 year ago

Disable all the other extensions except for LaTeX Workshop and LaTeX Utilities, and check that you still see this issue.

You still see this issue?: Yes

Describe the bug

Hi!

When I copy/paste (or drag&drop holding shift) an image to my latex document, only the path of the image is copied. I tried when setting graphicspath, but nothing changed.

Desktop

leoleoasd commented 1 year ago

How do you paste the image? Did you call formattedPaste command or just Ctrl-C?

quentgoutaland commented 1 year ago

I tested both (all other extensions disabled). I called formattedPaste from the command palette but it also copied the path. I also tried replacing the default template with the one given in the demo and get the same result.

leoleoasd commented 1 year ago

Can you check the "output" panel? There should be something like this:

[20:44:56] formattedPaste
[20:44:56] Performing formatted paste
[20:44:56] Pasting: Image
[20:44:56] ./images/
[20:44:56] ./images/
[20:44:56] ./images/
quentgoutaland commented 1 year ago

Here it is. It seems, it does not consider my .jpg as an image.

[14:50:51] formattedPaste [14:50:51] Performing formatted paste [14:50:51] Pasting: Table [14:50:51] Failed to find delimited table [14:50:51] Doesn't look like a table [14:50:51] Failed to find , delimited table [14:50:51] Doesn't look like a table [14:50:51] Failed to find | delimited table [14:50:51] Doesn't look like a table [14:50:51] No table found

leoleoasd commented 1 year ago

I dont have a Linux desktop to test this. Can you try pasting it elsewhere? The image pasting process only begins when the extension couldn't find text in your clipboard. On other OS this seems ok. Maybe on Linux we need another way to test if there is an image in the clipboard?

leoleoasd commented 1 year ago

And please try if this script can save your image by:

./saveclipimg-linux.sh filename.jpg
ls filename.jpg
quentgoutaland commented 1 year ago

When I clean my clipboard and trigger FormattedPaste from the command palette, I am prompt to enter the image name. Since there is no image in my clipboard, nothing is copied and I get the message "no image found in clipboard". With the above script executed after I copied an image (with Ctrl + C), it seems to paste the file, but it is empty.

leoleoasd commented 1 year ago

When I clean my clipboard and trigger FormattedPaste from the command palette, I am prompt to enter the image name. Since there is no image in my clipboard, nothing is copied and I get the message "no image found in clipboard".

this is the expected behavior

With the above script executed after I copied an image (with Ctrl + C), it seems to paste the file, but it is empty.

This seems pretty weird 🤔

quentgoutaland commented 1 year ago

Here is an example (before/after I execute the script)

before_clipx

after_clipx

leoleoasd commented 1 year ago

This command saves image in your clipboard to filename.jpg.

leoleoasd commented 1 year ago

Also, pasting image files isn't supported (yet, on linux, see #363, #364 and #358). Make sure you have image in your clipboard.

quentgoutaland commented 1 year ago

Ok, so it did save the image to my clipboard. Then using FormattedPaste from the palette still copy the path.

leoleoasd commented 1 year ago

I'll try fix this after I refactor some old code

quentgoutaland commented 1 year ago

Ok, thanks!

leoleoasd commented 1 year ago

fix.zip @quentgoutaland Can you try this vsix?

quentgoutaland commented 1 year ago

Copy the file and pasting using the palette works almost as expected (it first pastes the path and then the image template is activated). Drag&drop still paste the path (but I assume the functionality is not supported for Linux).

leoleoasd commented 1 year ago

can you try pasting image on that vsix? Pasting file and drag&drop isn't supported.

quentgoutaland commented 1 year ago

Pasting using (Ctrl + V or Ctrl + Alt + V) gives the same result as the palette:

For the output when FormattedPaste is used: [08:56:31] withTelemetry: formattedPaste [08:56:31] Performing formatted paste [08:56:31] Pasting: Image. imgFile: undefined [08:56:31] Pasting: Table [08:56:31] Failed to find delimited table [08:56:31] Doesn't look like a table [08:56:31] Failed to find , delimited table [08:56:31] Doesn't look like a table [08:56:31] Failed to find | delimited table [08:56:31] Doesn't look like a table [08:56:31] No table found [08:56:31] withTelemetry: onDidChangeTextDocument [08:56:31] withTelemetry: onDidChangeTextDocument [08:56:37] Image path: ~/test/java_convention.png [08:56:40] save and paste. imagePath: ~/test/java_convention.png [08:56:40] withTelemetry: onDidChangeTextDocument [08:56:46] withTelemetry: onDidChangeActiveTextEditor_tex_wordcounter

leoleoasd commented 1 year ago

fix.zip @quentgoutaland can you try this one, use command palette and post all logs

quentgoutaland commented 1 year ago

It seems to work correctly! The path is not pasted, when I trigger the palette it asks me the name of the image and pastes it using the template.

[09:13:01] withTelemetry: formattedPaste [09:13:01] Performing formatted paste [09:13:01] Pasting: Image. imgFile: undefined [09:13:12] Image path: ~/test/figures/DSCF0627.jpg [09:13:12] save and paste. imagePath: ~/test/figures/DSCF0627.jpg [09:13:12] paste image success. returning

leoleoasd commented 1 year ago

Does it fix your problem?

quentgoutaland commented 1 year ago

Yes! Thank you!