purescript / pursuit

Website for hosting and searching PureScript API documentation
https://pursuit.purescript.org/
Other
170 stars 47 forks source link

Add button "copy import statement to clipboard" #438

Open flip111 opened 3 years ago

flip111 commented 3 years ago

Would be nice to have a small button next to functions (and other things) to format an import statement and copy it to the clipboard

flip111 commented 1 year ago

Could be added here in the code https://github.com/purescript/pursuit/blob/3209916030e5bae48d4e77e7ee1e6ee833192a1b/src/Handler/Search.hs#L319

JordanMartinez commented 1 year ago

I kind of find it hard to justify this because I feel like this is a very rare use case. Put differently, is this just going to clutter up the UI if we add a button like this?

flip111 commented 1 year ago

Screenshot from 2023-01-31 23-08-04

Something like this, but better designed button. Probably could go on the module page too (screenshot is from search). Button could also be placed top-right similar to where Source is located next to functions in module docs.

I think the use case of looking up docs and then typing module name and function name into your code is very frequent. Now i usually scroll to top of page, copy the module name. And then i do this import <CTRL + V> (<function name i remembered>).

@JordanMartinez how does your workflow look like?

JordanMartinez commented 1 year ago

:facepalm: I literally thought this issue was on the Try PureScript repo...

Ok. The copy import button does make sense.

JordanMartinez commented 1 year ago

What are your thoughts on making the proposed button also copy it as a qualified import that the user defines? So,

  1. user interacts with the button (e.g. Ctrl+Click to trigger this behavior)
  2. an input appears and is focused
  3. user types in some alias (e.g. "Functor") and types Enter
  4. the following is copied to your clipboard:
    import Data.Functor as Functor
flip111 commented 1 year ago

Seems like a good idea to me :)

I'm thinking whether it would pay off to have a toggle (i.e. checkbox) to enable/disable the popup somewhere (toggle state stored on the browser)

JordanMartinez commented 1 year ago

:man_shrugging: I don't know, but I would focus on getting your original idea in first. Otherwise, it may never get implemented due to focusing too much on my suggestions.