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

Move formatted paste to LaTeX Utilities, add api to get graphics path #1478

Closed
wants to merge 11 commits into from
Closed

Move formatted paste to LaTeX Utilities, add api to get graphics path #1478

wants to merge 11 commits into from

Conversation

tecosaur
Copy link
Contributor

@tecosaur tecosaur commented Jul 4, 2019

Note: this started off as image pasting, to see what happend read the block of comments at the end. I'll leave the original PR text below

Now introducing, the ability to directly paste images into LaTeX files

Summary

  • Can now paste images from clipboard to file!!! (yay)
  • Adds shortcut cmd+v, just pastes normally unless blank (in which case it tries an image)
  • Clipboard to file accomplished via calling short os-specific scripts
  • This works but could maybe do with a bit of refinement

Background

To me this is a "Yes! Finally, this is fantastic!" type feature, however as seen by how heated #1452 became obviously not everyone shares my enthusiasm.

Justification

Simplification of the image inclusion process

Old Process

  1. Right click, save image to file
  2. Navigate to graphics folder
  3. Give file name
  4. Copy file name
  5. Go to latex file
  6. Trigger sniper for inserting figure / image
  7. Paste file name

New Process

  1. Right click, copy image
  2. Paste into vscode

Demand / Support in other editors

Maintainability

Structure of new feature

When pasting an image there are seven main methods called:

  • pasteImage
  • loadImageConfig
  • replacePathVariables
  • getImagePath
  • saveAndPaste
  • saveClipboardImageToFileAndGetPath
  • renderImagePaste

pasteImage

Just get's selection text and calls some of the other main functions.
As long as the other functions work this will to.

  • calling other class functions

Needs maintaining if: other class functions change

loadImageConfig

Bog standard reading config variables from vscode settings and then applying replacePathVariables

  • vscode config reading

Needs maintaining if: vscode api introduced drastic breaking changes

replacePathVariables

Just performs a bunch of text replacements.

  • String manipulation
  • Requires this.extension.completer.input.graphicsPath

Needs maintaining if: this.extension.completer.input.graphicsPath changes

getImagePath

Uses selected text or config + user to determine image path.

  • String / path manipulation.

Needs maintaining if: path introduces drastic breaking changes

saveAndPaste

Calls ensureImgDirExists which just uses fse, then either runs fsCopy/fsRename or saveClipboardImageToFileAndGetPath.

  • fs/fse
  • calling saveClipboardImageToFileAndGetPath

Needs maintaining if: fs/fse introduces drastic breaking changes

saveClipboardImageToFileAndGetPath

Uses spawn from childprocess, calls short os-specific scripts.
Scripts are short and simple, should be quite stable.

Needs maintaining if: childprocess depreciates spawn or clipboard interaction method with os drastically changes (unlikely)

renderImagePaste

Uses config from loadImageConfig then does text replacement.

Needs maintaining if: text replacement config scheme changes

Maintainability conclusion

Shouldn't require much.

@tamuratak
Copy link
Contributor

I am against this PR as I explained in the previous PR. I do not want to continue the discussion as I have explained enough. I think this is up to the authors, @James-Yu @jlelong, now.

@tecosaur
Copy link
Contributor Author

tecosaur commented Jul 7, 2019

@James-Yu @jlelong it would be good if you could give some feedback on this PR.

@tecosaur tecosaur mentioned this pull request Jul 7, 2019
@James-Yu
Copy link
Owner

James-Yu commented Jul 8, 2019

I may need a bit of time to go through it. Please remind me if I did not show up in a few days.

@tecosaur
Copy link
Contributor Author

@James-Yu *cough

package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/main.ts Outdated Show resolved Hide resolved
src/components/paster.ts Outdated Show resolved Hide resolved
@tecosaur
Copy link
Contributor Author

Thanks @James-Yu I'll go through all of those either tonight or tomorrow :)

@tecosaur
Copy link
Contributor Author

@James-Yu let me know if that's better now, and if you'd like any more changes.

@tecosaur
Copy link
Contributor Author

@James-Yu *cough

@jlelong
Copy link
Collaborator

jlelong commented Jul 14, 2019

As @tamuratak, I am still not convinced by the Paste from clipboard function. This is true that this feature has been requested in other LaTeX extensions but it is not clear at that it has been implemented.

Sublime Text's LaTeX Tools had image copy/paste requested and added here SublimeText/LaTeXTools#1154

Not clear that pasting from clipboard has indeed been implemented but rather only pasting a file path.

TeXstudio had it requested here https://sourceforge.net/p/texstudio/feature-requests/1092/

But not implemented

AUCTeX had it added in this thread https://lists.gnu.org/archive/html/auctex/2010-12/msg00010.html

It does not seem to have been integrated into AUCTeX.

Anyway, if you believe pasting from clipboard is important, it goes beyond LaTeX and there are indeed several vscode extensions to achieve this. In particular, it looks like https://github.com/mushanshitiancai/vscode-paste-image could do it almost out of the box.

@tecosaur
Copy link
Contributor Author

tecosaur commented Jul 14, 2019

@jlelong Yea, I have mixed feelings on this too; particularly given that https://github.com/mushanshitiancai/vscode-paste-image exists. Ultimately what made me think it's worth going in this direction is that it fits with my view of this extension as a "one stop shop" for the functionality you'd want with LaTeX documents.

It does not seem to have been integrated into AUCTeX.

Re: AUCTeX for it being integrated you need to skip to https://lists.gnu.org/archive/html/auctex/2010-12/msg00015.html where I saw "I integrated it into auctex/tex.el and it is working nicely" and then the discussion continues in further threads. At least I assume this means it was integrated into AUCTeX 🤷‍♂️.

@tamuratak
Copy link
Contributor

tamuratak commented Jul 14, 2019

@tecosaur stop such an argument. With your argument, we must include every function requested by users. Nonsense. We must decide which one to integrate with LaTeX Workshop.

@tecosaur
Copy link
Contributor Author

I usually see adding functionality requested by users to be a good thing 😛 but yes — definitely can be a slippery slope in some cases. Anyway, I don't think there's much point in me discussing this further so I'll just wait untill James decides to weigh in.

@jlelong
Copy link
Collaborator

jlelong commented Jul 15, 2019

Aiming at building the All-In-One extension for LaTeX may sound a promising idea but it may turn into a trap because it will lead the extension to grow far too much. We must always weigh the benefit for most users of introducing a feature versus the maintainability issues and potential bugs.

Concerning this PR, I do believe that it would better fit directly into https://github.com/mushanshitiancai/vscode-paste-image as making the LaTeX support would only be a small add-on. Modularity is always good practice in software design. Before going any further, I would suggest @tecosaur to get in touch with the maintainers of https://github.com/mushanshitiancai/vscode-paste-image.

@tecosaur
Copy link
Contributor Author

@jlelong I think that sounds like a good way of handling this. Hence, this is my revised plan

// almost-code
if (clipboard.text === '') {
    try {
        vscodeExecuteCommand('vscode-paste-image.paste')
    } catch (e) {
        vscodeShowMessage('Install vscode-paste-image to be able to paste images')
    }
}

@tecosaur
Copy link
Contributor Author

Addendum. The one bit I wouldn't be sure how to do would be passing the reference for graphicsPath over. Would anyone have any suggestions for that?

@James-Yu
Copy link
Owner

While I am interested in seeing this feature, I totally agree with @jlelong on modularity and maintainability. Let's see if the other extension would incorporate the main logic so that we only need to have a minimal adapter.

@tecosaur
Copy link
Contributor Author

I have created mushanshitiancai/vscode-paste-image#50 and I'll report back when something's happening 😃

@tecosaur
Copy link
Contributor Author

Ok. It's now been five days and I haven't seen any sign of a response. Looking at other open issues, the last few haven't got any response either (Going back to early May). Hmmm, I'm not sure how to proceed from here. @James-Yu any thoughts?

@tamuratak
Copy link
Contributor

@tecosaur make your own extension.

@tecosaur
Copy link
Contributor Author

Done. This now just contains an adaptor + some formatting changes that slipped in.
@James-Yu how would you feel about merging this now?

@tamuratak
Copy link
Contributor

Why do we need this change on LaTeX Workshop's side? You misunderstand James' idea #1544 (comment). LaTeX Utilities uses some API exposed by LaTeX Workshop. Not the opposite. If changes on LaTeX Workshop's side are necessary on every new feature by LaTeX Utilities, the maintainability of LaTeX Workshop does not get better.

@tecosaur
Copy link
Contributor Author

@tamuratak Other than the API revealing on this extension's side, changes are not required for this feature. The feature works with just LaTeX Utilities using the "Paste an Image File" command. I do not see this as indicative of how other feature will be either, take the "Live Reformatting" — that is also implemented in LaTeX Utilities and requires no change this side.

However, it makes logical sense that when you paste an image path the same thing happens as with CSVs etc. and if you have an image in the clipboard "formattedPaste" would logically be the command to insert it into the document, and to have the user remember yet another shortcut seems wholly unnecessary. I also fail to see any real maintinence cost induced by effectively adding four lines twice.

if (this.extension.utilities) {
    this.extension.utilities.exports.pasteImage()
} else {
    vscode.window.showInformationMessage('Install LaTeX Utilities to paste images')
}

I must say, to me it seems a bit ridiculous to be concerned about the 'maintinence cost' of that.

In James's comment he talkes about modularising features. This has been done. I see now reason why we can't add a very small number of simple lines to make things work better though.

@tamuratak
Copy link
Contributor

When another person with a fancy idea "Paste X" appears, they will want another change on LaTeX Workshop's side. You have to discuss with each other which "Paste X/Image" to prioritize in LaTeX Workshop's side. That is a kind of increase in the maintenance cost of LaTeX Workshop. We can avoid such a thing with an appropriate API.

Please think about what kind of API exposed by LaTeX Workshop will solve your problem.

@tecosaur
Copy link
Contributor Author

Thank you for explaining that @tamuratak. I was thinking of it as just this single feature.
Perhaps if we want to fully follow the idea mentioned earlier (in the live reformatter PR)

  • LaTeX Workshop; gives you all the basics to get started with LaTeX in vscode without too much hassle
  • LaTeX Untilities; all collection fancy ease-of-life features that the majority of users may not use, but a significant number of people will be very interested in

Then the best place for the "formattedPaste" feature itself woud be in LaTeX Utilities? It would definately make it much cleaner to add future pasting capability in the Utilities extension if the formatted paste feature is there.

What do you think?

@James-Yu
Copy link
Owner

I would vote yes for moving all formatted paste features to utilities. That makes it more clear.

@tecosaur
Copy link
Contributor Author

Ok. I think that should resolve all of this rather nicely. I'll move it tonight.

@tecosaur tecosaur changed the title Add image pasting functionality Move formatted paste to LaTeX Utilities, add api to get graphics path Jul 31, 2019
@James-Yu
Copy link
Owner

Besides this, we may also think of what existing features may be better re-positioned in LaTeX Utilities. To name one, the word counter feature is way too isolated and may be good as a module in LU.

@tecosaur
Copy link
Contributor Author

To me (regarding which features should be where) I think the first question that should be asked is the approach. To me, there are three main ways we can go about labelling issues as Workshop or Utilities.

  1. Identify all the 'core' / essential features. All other features are labelled extra and should be moved to Utilities
  2. Identify all 'extra' features. These features are moved to Utilities. All other features are labelled 'core'.
  3. List all features. Go through and label as 'core' or 'extra', move extra to Utilities.

@James-Yu
Copy link
Owner

I am implicitly taking the third approach. Will have more PRs to LU in a few days.

@tamuratak
Copy link
Contributor

tamuratak commented Aug 1, 2019

@tecosaur This PR includes too many unrelated changes. Please create a new PR of moving formattedPaste to LU for an accurate history.

@James-Yu please create a new issue for these discussions if you will continue.

@tecosaur
Copy link
Contributor Author

tecosaur commented Aug 1, 2019

I think I a new issue should be used for the discussions, I can't imagine that this is the end. Let's move to #1558

Repository owner locked as resolved and limited conversation to collaborators Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants