Closed Bug 1769936 Opened 4 years ago Closed 4 years ago

Add a button or shortcut to copy the selected code block with permanent link

Categories

(Webtools :: Searchfox, enhancement)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 external file)

During explaining the code flow in bug comment I often do the following:

  1. open a specific line in searchfox, by serching with word, or following "Search for function" or "Go to definition of" links. e.g. https://searchfox.org/mozilla-central/source/js/src/vm/CodeCoverage.cpp#500
  2. select lines that I want to refer, by:
    1. click "499" text for line 499
    2. shift-click "502" text for line 502
  3. hit "y" key to get permanent link
  4. copy the URL to text editor
  5. copy lines 499-502, and paste it under the URL, enclosing it with triple-backticks, to get the following block
  6. go back to non-permanent link URL, by browser "back" feature
  7. go to step 1 and do the same for all relevant code blocks

Example of what I want to get in bug comment:

https://searchfox.org/mozilla-central/rev/8fe6930c0832009b3162bebee7d4ede1a4c8c9a8/js/src/vm/CodeCoverage.cpp#499-502

void InitLCov() {
  const char* outDir = getenv("JS_CODE_COVERAGE_OUTPUT_DIR");
  if (outDir && *outDir != 0) {
    EnableLCov();

and I wonder if the steps 3-6 can be done automatically, such like:

  1. open specific line in searchfox
  2. select lines
  3. hit some key to copy the URL + code block into clipboard
  4. paste it to text editor
  5. go to step 1

This would definitely be a fantastic and useful addition! I also frequently find myself constructing [ClassName::MethodName](permalink to source listing) or [ClassName::MethodName](permalink to searchfox search for the method to bring up the search results) boilerplate that I think could be very useful to support automating.

Note that since https://github.com/mozsearch/mozsearch/pull/377 there are "copy" icons to the right of each of permalink/log/raw in the navigation panel, and for permalink this will copy a permalink for the current file and active line-selection to the clipboard without changing the URL. Note that there isn't an equivalent hotkey for this at the current time, but that could make sense as something to support given that it involves a fair amount of mouse travel.

In the medium term it's likely we'll be super-charging the navigation panel to support a bunch of optional panels (basic mockup here), plus adding a settings page so that people can potentially control how they might want features like this to work (or whether to show-up in the UI), so I think it's very possible for us to move forward with something like this without having to worry too much about people being upset about new UI affordances!

If you'd like to dig into how this works right now to look at prototyping this:

  • https://github.com/mozsearch/mozsearch has docs on how to get a VM set up so that you can locally hack on a small test corpus that allows for a fairly quick dev cycle.
  • https://github.com/mozsearch/mozsearch/blob/master/static/js/panel.js is the logic that binds to the HTML panel we build.
  • here in src/bin/output-file.rs is where we populate the "other tools" panel nodes, after populating the VCS panel items.
  • here in static/js/code-highlighter.js is where we update the hash and do dynamic things in response to the line selection like calling the DocumentTitler which dynamically updates the document title to try and be helpful (but which I have some regrets about and will be something user configurable in the medium term via that new settings page).
  • I'd guess that there'd want to be some dynamic logic in the highlighter to enable one or more UI options when they become relevant thanks to the selection. I suspect it might be less jarring for the panel items to already exist but be disabled if they don't make any sense at the current time rather than having the navigation panel resize itself. Although maybe their text might update somewhat? NI-ing :emilio for feedback. As an example, there might be a bunch of options we could have:
    • Markdown link to lines - A markdown link just to the lines that has a shortened filename?
    • Markdown line excerpt - A markdown link with the triple-backticked code excerpt (with the language identifier baked in based on file extension for supported file extensions).
    • Symbol markdown link - A markdown link that tries to pick the symbol that it thinks you're linking to; this could be based on the current hacky DocumentTitler logic that actually does a pretty good job of figuring out the symbol name of the line you click on.
Flags: needinfo?(emilio)

Thank you for the details :)
I'll take this.
locally it's almost working.

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED

Yeah, not sure I'd go for a very complicated set-up. Having a disabled-by-default "Copy markdown block" or something that gets enabled if there's any line selected would be great. Bonus points for making it also react to the actual text selection I guess. That shouldn't be too complicated with selectionchange events and so but probably can be follow-up work :)

Flags: needinfo?(emilio)
Attached file GitHub Pull Request —

(In reply to Emilio Cobos Álvarez (:emilio) from comment #3)

Bonus points for making it also react to the actual text selection I guess. That shouldn't be too complicated with selectionchange events and so but probably can be follow-up work :)

How would that work?
in the PR, I just used the entire line for each selected line.

Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Depends on: 1770501
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: