Edgewall Software

Ticket #7055 (assigned enhancement)

Opened 5 months ago

Last modified 5 weeks ago

Add "toggle line numbers" JavaScript to source browser

Reported by: benhoyt Owned by: cboos
Priority: low Milestone: 0.12
Component: general Version: devel
Severity: normal Keywords: review
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 5 months ago.
Expanding a bit on Ted Gifford's approach
hide_annotation_columns-r6692.2.diff (4.6 kB) - added by cboos 5 months ago.
Cleaned-up version, feature is now also enabled for attachments

Change History

Changed 5 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 5 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 5 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 5 months ago by nkantrowitz

  • cc nkantrowitz added

Changed 5 months ago by cboos

Expanding a bit on Ted Gifford's approach

Changed 5 months ago by cboos

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

Changed 5 months ago by cboos

  • keywords review added

Changed 5 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 5 months ago by benhoyt

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

Changed 5 months ago by trac@…

  • cc trac@… added

Changed 5 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 5 weeks 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.

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

Author



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