Page MenuHomePhabricator

Code gets copied double-spaced on new syntax-highlighted pages on Firefox
Closed, ResolvedPublic

Description

T29531: Implement link anchors to line numbers on syntax-highlighted pages (e.g. .css, .js) has made copying code on Firefox very inconvenient.

Steps to reproduce:

  • Open a syntax-highlighted page, e.g. en:MediaWiki:Common.css with Firefox (or any Gecko-based browser, I assume)
  • Copy multiple lines, e.g. first 4 lines

Actual result (clipboard content):

/* Reset italic styling set by user agent */

cite, dfn {

	font-style: inherit;

}

Expected result:

/* Reset italic styling set by user agent */
cite, dfn {
	font-style: inherit;
}

Now I have to open the code editor, manually remove the empty lines, or switch to Chrome in order to copy a chunk of code as it's written.

Event Timeline

Nardog created this task.Jan 9 2021, 8:51 AM
Restricted Application added subscribers: Universal_Omega, Aklapper. · View Herald TranscriptJan 9 2021, 8:51 AM

Well that's annoying. I can see no reason for FF to add those linebreaks, and I've tried messing around with the styling of the numbers (resetting white-space:pre on them, using different display values) to no avail.

Should probably file an upstream issue, but in the meantime we can use a JS workaround by hiding the line numbers when a copy event is triggered.

Actually it turns out that the previous hack of user-select:none is causing FF to split the selection into multiple ranges, which adds the linebreaks. Removing that hack fixes FF.

Change 657185 had a related patch set uploaded (by Esanders; owner: Esanders):
[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Line number selection: Remove user-select:none

https://gerrit.wikimedia.org/r/657185

Test wiki created on Patch Demo by ESanders (WMF) using patch(es) linked to this task:

http://patchdemo.wmflabs.org/wikis/b47a017de5c94e68321e246f05fbd175/w/

Jdforrester-WMF closed this task as Resolved.Jan 19 2021, 11:40 PM
Jdforrester-WMF assigned this task to Esanders.

Change 657185 merged by jenkins-bot:
[mediawiki/extensions/SyntaxHighlight_GeSHi@master] Line number selection: Remove user-select:none

https://gerrit.wikimedia.org/r/657185