Make code line numbers work as links
Review Request #5576 — Created March 3, 2014 and submitted
I added two functions to the file, one adds the links to the code line numbers and the another one removes the link when the code line number isn't hovered. The link is combined from the file id and the line number, which should be enough to identify the row, which should be highlighted. The link is removed from the th element, when user hovers on another row. I'm not sure if this is ideal solution, but otherwise the link keeps flicking every time the cursor moves even a bit.
The hackpad link -> (https://reviewboard.hackpad.com/Diffviewer-Line-Link-Project-Spec-jPwinbJva3E).
Testing is done on my development server. There is also two screen shots below to demonstrate, how the link is presented.
Description | From | Last Updated |
---|---|---|
Should the ghostflag show also here, when the code line link is generated? Though the ghostflag will show up, if … |
AU Audore | |
We use LessCSS, which allows you to nest rules in some convenient ways. This code can be rewritten as: a … |
chipx86 | |
Several issues with style that you'll need to fix up for all of your code: 1) Braces always go on … |
chipx86 | |
You should only ever have one var statement, and it should be at the very top of the function. In … |
chipx86 | |
You'll want to use this.getLineNum. You also have a lot of code in here doing things that aren't necessary. For … |
chipx86 | |
Looks into more of our functions and variables available in this class, like _getActualLineNumCell. You can reuse some of what … |
chipx86 | |
Make sure you're using single-quote strings and not double-quote wherever possible. |
chipx86 | |
Spaces around +. |
chipx86 | |
You're building this string in a couple places. I can't really tell why. Can you explain what that's doing? You … |
chipx86 | |
You need to be sure you're indenting when a statement spans multiple lines. Also, you should never need to call … |
chipx86 | |
Blank line before this. |
chipx86 | |
Careful about trailing whitespace. Go through your change and clean those up. |
chipx86 | |
These blank lines should go away. |
chipx86 | |
Similar comments as above. |
chipx86 | |
Blank line between these. |
chipx86 | |
I'm having trouble to implement this. This works fine if the diff is only one lined, but if there's two … |
AU Audore | |
You don't need to recurse like this. Just do: $row.find('.copylink') |
chipx86 | |
Get rid of these blank lines. |
chipx86 | |
I'm having trouble to implement this. This works fine if the diff is only one lined, but if there's two … |
AU Audore | |
Here I'm trying to declare the variables used in templates. |
AU Audore | |
Here i'm trying to bind the variables to the template. It's not working.. |
AU Audore | |
Here I try to use the template, so I woudn't pollute it with the same dom code over and over … |
AU Audore | |
I think your bug is that you're not passing linkToRow into this invocation of the template: ```javascript this._$link = $(this.linkTemplate({ … |
david | |
This isn't needed. |
chipx86 | |
I want to see this like other templates: <th> <a href .....> </th> |
chipx86 | |
These names are pretty generic and specific to the link code. Maybe oldLinkLineNum and oldLinkRow? |
chipx86 | |
Need a space after the comma. |
chipx86 | |
One variable per line. |
chipx86 | |
You still have an extra space before the === |
chipx86 | |
Blank line between these. |
chipx86 | |
Doing $myel[0].id is faster than $myel.attr('id'). |
chipx86 | |
Multi-line comments must be in the form of: /* * First line * Second line * ... */ Same with … |
chipx86 | |
You're querying 'th' all over the place, in multiple ways. Each time you query, it has to do some expensive … |
chipx86 | |
Same with the comment flags. |
chipx86 | |
As per my prior comments in other reviews, you don't need to be using .first() and .last() almost ever. Make … |
chipx86 | |
Indentation when chaining should be like: $row.children('th') .replaceWith(this.linkTemplate({ ... })); This applies all over the place. |
chipx86 | |
What's the difference between this and the ones above? Some extra, clear commenting would help a lot with the complexity … |
chipx86 | |
No blank line here. |
chipx86 | |
You have an extra space before the ) |
chipx86 | |
Blank line between these. |
chipx86 | |
We only want one var statement. |
chipx86 | |
Again, you're querying for stuff too many times. You need to condense these all down. |
chipx86 | |
This is already a <th>. You can just do: $row.find('th').text(lineNum); Same elsewhere. |
chipx86 | |
Don't add random blank lines in the file. You should go through and remove the unrelated code changes. |
chipx86 | |
Why did you do this? Those lines were very important. I can't imagine things are working without them. |
chipx86 | |
Please put a blank line between these two statements. |
david | |
Please put a blank line between these two statements. |
david | |
I think the alignment here will be easier to do cleanly if you break it into two statements. How about … |
david | |
There should be a space after the ":" in object literals. |
david | |
Typo in "exist". Also, please add a space after the '.' |
david | |
Please add a space after the '.' |
david | |
Can you put the })); on the next line? |
david | |
Can you separate these with a blank line? |
david | |
Can you put the })); on the next line? |
david | |
Same comments as in the previous method. |
david | |
Can you add a blank line here? |
david | |
After trying this out, I think that having the link show in underlined blue is very distracting, especially in cases … |
david | |
These two variables aren't used--you can get rid of them. |
david | |
In testing this, I noticed that mousing over the new link would de-highlight the row. The issue is that this … |
david | |
Because we're now expecting people to use the right button in the line number rows, this code should be wrapped … |
david |
- Change Summary:
-
Code line number link style added and some functionality fixed, only the ghost commentflag doesn't show up when hovering over code line number link.
-
-
We use LessCSS, which allows you to nest rules in some convenient ways. This code can be rewritten as:
a { color: black; text-decoration: none; &.copylink { ... } }
-
Several issues with style that you'll need to fix up for all of your code:
1) Braces always go on the previous line, like:
if (...) {
2) Space after the
if
3) Be careful about extra spaces in the code (you have two before the
==
)4) In JavaScript, you almost always want to compare using
===
and!==
, not==
and!=
. -
You should only ever have one
var
statement, and it should be at the very top of the function. In JavaScript, you want to pre-declare all your variables (since internally, JavaScript will try to do that for you, which can lead to bugs). -
You'll want to use
this.getLineNum
.You also have a lot of code in here doing things that aren't necessary. For example, you should never have to call
.filter(function() { ... })
for anything, and you likely don't need to call.first()
for anything here. Or.contents()
. -
Looks into more of our functions and variables available in this class, like
_getActualLineNumCell
. You can reuse some of what we've already built.Also, note that you can call
.parents('table')
and similar to get a specific parent without having to go up each level manually. -
-
-
You're building this string in a couple places. I can't really tell why. Can you explain what that's doing?
You also don't want to build this by hand here. Look at how we do templates in JavaScript (search for
_.template
). You'll want to create one for this and pass in the variables it'll use to build the entire string. -
You need to be sure you're indenting when a statement spans multiple lines.
Also, you should never need to call
.contents()
or.filter
. -
-
-
-
-
-
-
-
-
I'm having trouble to implement this. This works fine if the diff is only one lined, but if there's two lines and commentflags, getting the first/second (the one which isn't in tr attribute line) line number gets really difficult.
-
I'm having trouble to implement this. This works fine if the diff is only one lined, but if there's two lines and commentflags, getting the first/second (the one which isn't in tr attribute line) line number gets really difficult.
- Change Summary:
-
Added the template code, which produces the following error:'Uncaught ReferenceError: linkToRow is not defined'
-
The biggest thing distracting me as I read this change is that your code is wildly inconsistent with the rest of the file, in terms of code style. When working on an existing codebase, it is very important that you make sure you are completely consistent. It should be impossible to tell what code you wrote on vs. what code was already there.
That includes things like:
- Number of spaces used for indentation (4)
- Make sure there's a space after
if
andfor
(noif()
) - Location of opening braces
- Location of ending braces
- One variable per line on
var
declarations - Line lengths (< 80 columns)
- Where blank lines go (also important not to randomly add or remove blank lines in unrelated parts of the file)
- Spaces after commas
Go through and make sure your code completely fits in with our code, and make sure that every single line you write from here on out also fits in. This is going to be an extremely important skill in the industry, where consistency is almost always required.
-
Nearly all the comments mentioned here apply in more than one place in the file. Make sure you go through in detail.
-
-
-
-
-
-
-
-
-
Multi-line comments must be in the form of:
/* * First line * Second line * ... */
Same with your other multi-line comments.
-
You're querying 'th' all over the place, in multiple ways. Each time you query, it has to do some expensive lookups. Make sure you only query once per thing you're trying to get.
-
-
As per my prior comments in other reviews, you don't need to be using
.first()
and.last()
almost ever. Make sure it's actually required when you use it. -
Indentation when chaining should be like:
$row.children('th') .replaceWith(this.linkTemplate({ ... }));
This applies all over the place.
-
What's the difference between this and the ones above?
Some extra, clear commenting would help a lot with the complexity of all this.
(I know English isn't your first language, but if you have any friends who are proficient, you can ask them to proof-read. Or come to us in IRC.)
-
-
-
-
-
-
-
Don't add random blank lines in the file. You should go through and remove the unrelated code changes.
-
Why did you do this? Those lines were very important. I can't imagine things are working without them.
- Change Summary:
-
Styling changes and refactoring the code
- Commit:
-
f04563b04505898ece4d435f49333c8ec5780b45
- Change Summary:
-
Spaces added, now every issue should be fixed.
- Commit:
-
f04563b04505898ece4d435f49333c8ec5780b45d29fe9be727d9dd9d39ce3c26107f436ca8326b7
- Change Summary:
-
Moved out of WIP, all issues cleared and two screen shots added.
- Summary:
-
[WIP] Make code line numbers work as linksMake code line numbers work as links
- Description:
-
~ I added two functions to the file, one adds the links to the code line numbers and the another one removes the link when the code line number isn't hovered. This is still early implementation of the part 1 (https://reviewboard.hackpad.com/Diffviewer-Line-Link-Project-Spec-jPwinbJva3E).
~ ~ I added two functions to the file, one adds the links to the code line numbers and the another one removes the link when the code line number isn't hovered. The link is combined from the file id and the line number, which should be enough to identify the row, which should be highlighted. The link is removed from the th element, when user hovers on another row. I'm not sure if this is ideal solution, but otherwise the link keeps flicking every time the cursor moves even a bit.
~ The hackpad link -> (https://reviewboard.hackpad.com/Diffviewer-Line-Link-Project-Spec-jPwinbJva3E). - Should the code line numbers apperance be changed, when it contains the link?
- Testing Done:
-
+ Testing is done on my development server. There is also two screen shots below to demonstrate, how the link is presented.
- Removed Files:
- Added Files:
- Change Summary:
-
Style changes added according the comments
- Commit:
-
19eb1f398ad76689e6451e759b65d1ff5b50484fd5f9ecc6a7ca55383eb378fcc28a328cb8e6807b
-
-
After trying this out, I think that having the link show in underlined blue is very distracting, especially in cases where the event handling doesn't trigger the mouseout. I vote that we get rid of this and leave the appearance as-is.
-
-
In testing this, I noticed that mousing over the new link would de-highlight the row. The issue is that this code isn't properly accounting for the new
<a>
element.If you add something like this at the beginning of this method, it should cope with it:
// Navigate up out of <a class="copylink"> elements if ($node.hasClass('copylink')) { $node = $node.parent(); } ...
-
Because we're now expecting people to use the right button in the line number rows, this code should be wrapped inside
if (e.button === 1) { ... }
- Change Summary:
-
Removed the link styling and separated the right click and left click, what David suggested in his comments.
- Commit:
-
d5f9ecc6a7ca55383eb378fcc28a328cb8e6807b0ed8ba28a4dac0d457b6a3e06dd11370f8bc45ac