Edgewall Software

Ticket #7055 (closed enhancement: fixed)

Opened 8 months ago

Last modified 3 weeks ago

Add "toggle line numbers" JavaScript to source browser

Reported by: benhoyt Owned by: cboos
Priority: normal Milestone: 0.12
Component: general Version: devel
Severity: normal Keywords:
Cc: benhoyt@…, nkantrowitz, trac@…

Description

At the moment when you copy-n-paste code snippets from Trac's source browser (I often do) it also copies the line numbers, which is almost never what you want. To get code without the line numbers, you have to scroll down and click the "Plain Text" version, find your place again, and then do the copy and paste.

It'd be nice if the Trac source file browser had a little JavaScript link, called "Toggle line numbers", that toggled the line numbers on and off, making copy-n-paste really clean and simple. (The toggle link could be placed in the table cell to the right of the "Line" heading cell at the top-left of the table.)

See the further discussion (agreement?) on the trac-users group: http://groups.google.com/group/trac-users/browse_frm/thread/71da6e9b5554b89c

It shouldn't be much code, especially with jQuery -- Ted Gifford posted one possible solution: http://groups.google.com/group/trac-users/msg/846b21eb4e550e0a?dmode=source

Also see a somewhat related discussion on ticket:5779 about a "toggle line numbers" link in the diff viewer. They decided against it there, as normally you shouldn't need to copy-n-paste just a few lines of a diff or patch. (I find it's much more common with full source files, so believe the arguments against it for the diff viewer don't hold for the source viewer.)

BTW, not that I'd use it much, but I really like the operation of the "Tabular/Unified" button for the diff viewer in the new version of Trac. See an example of it at changeset:6599.

---Ben Hoyt (benhoyt.com)

Attachments

hide_annotation_columns-r6692.diff (3.7 KB) - added by cboos 8 months ago.
Expanding a bit on Ted Gifford's approach
hide_annotation_columns-r6692.2.diff (4.6 KB) - added by cboos 8 months ago.
Cleaned-up version, feature is now also enabled for attachments
7055-toggle-lines-r7656.patch (4.6 KB) - added by cboos 4 weeks ago.
Latest version of the show/hide columns patch

Change History

Changed 8 months ago by Kamil Kisiel <kamil@…>

I think that toggling the line numbers on and off for the purpose of copying kind of sucks. Take a look at the source browser on Google code. It displays line numbers, but when you select the code, the line numbers are not selected. You don't need to toggle them in order to copy.

Changed 8 months ago by benhoyt

Incidentally, I originally compared with Google Code too, and I'd prefer it that way as well. But as Matt Good said:

"This was considered a long time ago, but we opted in favor of making the source browser handle line-wrapping. The two options seem to be mutually exclusive. I've mentioned this trade-off to the Google Code developers since people complained a lot more when the lines did not wrap. You can always use the Plain Text link at the bottom to copy/ paste from. -- Matt"

So apparently that's already been discussed, and I guess there's pros and cons with that method. I think the "Toggle line numbers" option is the next-best option. :-)

Changed 8 months ago by benhoyt

Oops, forgot to mention where Matt Good said that. On the trac-users list, here: http://groups.google.com/group/trac-users/msg/6ffca928f4a1d09a

Changed 8 months ago by nkantrowitz

  • cc nkantrowitz added

Changed 8 months ago by cboos

Expanding a bit on Ted Gifford's approach

Changed 8 months ago by cboos

Cleaned-up version, feature is now also enabled for attachments

Changed 8 months ago by cboos

  • keywords review added

Changed 8 months ago by cboos

Just noticed a bug with 0pera (9.26 - Windows) when hiding both "Line" and "Rev" columns.

Works fine with Firefox 2.0.0.12, IE7, Safari 3.1.

Changed 8 months ago by benhoyt

Good work, cboos. I like open source. :-)

Changed 8 months ago by trac@…

  • cc trac@… added

Changed 8 months ago by cboos

  • milestone changed from 0.11.1 to 0.12

Note also that with this available, I could add an Author column in the blame view, disabled by default (the reason why there's no Author so far is precisely because 3 annotations columns took too much space).

Besides, this is an enhancement, so not for 0.11.1.

Changed 4 months ago by cboos

  • owner changed from jonas to cboos
  • status changed from new to assigned
  • milestone changed from 0.13 to 0.12

#2528 was closed since the ability to copy the source code without the line numbers will come as a bonus from this feature.

Btw, I have a fixed patch which works with Opera now, moving this to 0.12 as a reminder.

Changed 4 weeks ago by ebray

I've been using this patch for a while, and it works nicely for the most part. But I just noticed today that when annotation is enabled, clicking 'show line numbers' inserts the line numbers to the left of the annotation column instead of to the right.

Changed 4 weeks ago by cboos

Latest version of the show/hide columns patch

Changed 4 weeks ago by cboos

  • priority changed from low to normal

Erik, could you please try 7055-toggle-lines-r7656.patch? It seems to preserve the ordering of the columns, unlike the previous versions.

Changed 4 weeks ago by ebray

Thanks! I was just about to propose a similar patch that I was just working on. Works much better now.

Changed 3 weeks ago by cboos

  • keywords review removed
  • status changed from assigned to closed
  • resolution set to fixed

Applied in [7674], thanks for the feedback!

Add/Change #7055 (Add "toggle line numbers" JavaScript to source browser)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from cboos. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.