Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Update blame links with selected line, fix bug 1007293#563

Merged
pelmers merged 8 commits into
mozilla:masterfrom
pelmers:syn-clinks2
Jul 27, 2016
Merged

Update blame links with selected line, fix bug 1007293#563
pelmers merged 8 commits into
mozilla:masterfrom
pelmers:syn-clinks2

Conversation

@pelmers
Copy link
Copy Markdown
Contributor

@pelmers pelmers commented Jun 9, 2016

take 2! This time simplified from #448 (no format bump, mostly a javascript update).

Plugins can put {{line}} in the href of any links, and these will be substituted with the most recently selected line number.

@pelmers
Copy link
Copy Markdown
Contributor Author

pelmers commented Jun 21, 2016

It's all javascript!
r? @mythmon

$this.data('template', $this.attr('href'));
}
if (lastNumber) {
$this.attr('href', $this.data('template').replace(/{{line}}/g, lastNumber));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? I know that {} are special characters in some regex dialects. Not sure if it is a problem here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did work when I tested it locally. I think curlies are only used in {n} to match n occurrences of the preceding character.

@mythmon
Copy link
Copy Markdown

mythmon commented Jun 22, 2016

This seems like a fragile approach, since if the JS screws up you would get bad urls in your links. Maybe have the thing that generates the HTML fill in data-template directly with the template, and href with a safe fallback? That also simplifies the JS a bit.

@pelmers
Copy link
Copy Markdown
Contributor Author

pelmers commented Jun 22, 2016

Yes it would! I'll do that and ping you again

$this.attr('href', $this.data('template').replace(/{{line}}/g, lastNumber));
} else {
$this.attr('href', $this.data('template').replace(/{{line}}/g, ''));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can be a bit more concise here like this:

$this.attr('href', $this.data('template').replace(/{{line}}/g, lastNumber || ''));

@pelmers
Copy link
Copy Markdown
Contributor Author

pelmers commented Jul 6, 2016

@mythmon thanks for the reviews!


// Highlight any lines specified by hash in either a direct page load or a history pop.
$(document).ready(processHash);
$(document).ready(function() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wrap this in a function? The terser original form was equivalent, no?

@erikrose
Copy link
Copy Markdown
Contributor

My only reservation is that there's a hanging #L on any blame URLs that don't have a line number. It shouldn't hurt anything; it just looks shoddy. But it doesn't need to block merging this. r+. (And file a bug about the trailing #L.)

@pelmers
Copy link
Copy Markdown
Contributor Author

pelmers commented Jul 27, 2016

Thanks for review!

pelmers added a commit to pelmers/dxr that referenced this pull request Jul 27, 2016
@pelmers pelmers merged commit c58293b into mozilla:master Jul 27, 2016
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.

3 participants