Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/Linkifier.js

Issue 2644753002: DevTools: untruncate links on copy (Closed)
Patch Set: ac Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 * @param {!Element} anchor 296 * @param {!Element} anchor
297 * @param {!Bindings.LiveLocation} liveLocation 297 * @param {!Bindings.LiveLocation} liveLocation
298 */ 298 */
299 _updateAnchor(anchor, liveLocation) { 299 _updateAnchor(anchor, liveLocation) {
300 Components.Linkifier._unbindUILocation(anchor); 300 Components.Linkifier._unbindUILocation(anchor);
301 var uiLocation = liveLocation.uiLocation(); 301 var uiLocation = liveLocation.uiLocation();
302 if (!uiLocation) 302 if (!uiLocation)
303 return; 303 return;
304 304
305 Components.Linkifier._bindUILocation(anchor, uiLocation); 305 Components.Linkifier._bindUILocation(anchor, uiLocation);
306 var text = uiLocation.linkText();
307 var info = Components.Linkifier._linkInfo(anchor); 306 var info = Components.Linkifier._linkInfo(anchor);
308 info.originalLinkText = text; 307 info.originalLinkText = uiLocation.linkText(true /* skipTrim */);
309 text = text.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, '$1\u2026'); 308 var text = info.originalLinkText.replace(/([a-f0-9]{7})[a-f0-9]{13,}/g, '$1\ u2026');
310 if (this._maxLength) 309 if (this._maxLength)
311 text = text.trimMiddle(this._maxLength); 310 text = text.trimMiddle(this._maxLength);
312 anchor.textContent = text; 311 anchor.textContent = text;
313 312
314 var titleText = uiLocation.uiSourceCode.url(); 313 var titleText = uiLocation.uiSourceCode.url();
315 if (typeof uiLocation.lineNumber === 'number') 314 if (typeof uiLocation.lineNumber === 'number')
316 titleText += ':' + (uiLocation.lineNumber + 1); 315 titleText += ':' + (uiLocation.lineNumber + 1);
317 anchor.title = titleText; 316 anchor.title = titleText;
318 anchor.classList.toggle('webkit-html-blackbox-link', liveLocation.isBlackbox ed()); 317 anchor.classList.toggle('webkit-html-blackbox-link', liveLocation.isBlackbox ed());
319 Components.Linkifier._updateLinkDecorations(anchor); 318 Components.Linkifier._updateLinkDecorations(anchor);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 originalLinkText: text 411 originalLinkText: text
413 }; 412 };
414 if (!preventClick) 413 if (!preventClick)
415 link.addEventListener('click', Components.Linkifier._handleClick, false); 414 link.addEventListener('click', Components.Linkifier._handleClick, false);
416 else 415 else
417 link.classList.add('devtools-link-prevent-click'); 416 link.classList.add('devtools-link-prevent-click');
418 return link; 417 return link;
419 } 418 }
420 419
421 /** 420 /**
422 * @param {?Element} link 421 * @param {!Array<!Node>} nodes
423 * @return {?string} 422 * @return {string}
424 */ 423 */
425 static originalLinkText(link) { 424 static originalLinkText(nodes) {
lushnikov 2017/04/11 22:59:34 let's pass a link here
luoe 2017/04/12 22:00:37 Done.
426 var info = this._linkInfo(link); 425 var text = '';
427 return info ? info.originalLinkText : null; 426 for (var i = 0; i < nodes.length; i++) {
427 var info = this._linkInfo(nodes[i].parentElement);
428 text += info ? info.originalLinkText : nodes[i].textContent;
429 }
430 return text;
428 } 431 }
429 432
430 /** 433 /**
434 * @param {number} offset
435 * @param {!Node} node
436 * @return {number}
437 */
438 static selectionOffsetToOriginalOffset(offset, node) {
lushnikov 2017/04/11 22:59:34 selectionOffsetToOriginalTextOffset ?
lushnikov 2017/04/11 22:59:34 let's pass link here
luoe 2017/04/12 22:00:37 Done.
luoe 2017/04/12 22:00:37 Done.
439 var link = node.parentElement;
440 var info = this._linkInfo(link);
441 var originalLinkText = info ? info.originalLinkText : null;
442 if (originalLinkText === null)
443 return offset;
444
445 var truncatedLength = originalLinkText.length - link.textContent.length;
446 if (offset > link.textContent.length >> 1)
lushnikov 2017/04/11 22:59:34 /2
luoe 2017/04/12 22:00:37 Done.
447 offset += truncatedLength;
448 return offset;
449 }
450
451 /**
431 * @param {?Element} link 452 * @param {?Element} link
432 * @return {?Components._LinkInfo} 453 * @return {?Components._LinkInfo}
433 */ 454 */
434 static _linkInfo(link) { 455 static _linkInfo(link) {
435 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null); 456 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null);
436 } 457 }
437 458
438 /** 459 /**
439 * @param {!Event} event 460 * @param {!Event} event
440 */ 461 */
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 contextMenu.appendSeparator(); 801 contextMenu.appendSeparator();
781 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); 802 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false));
782 803
783 if (contentProvider instanceof Workspace.UISourceCode) { 804 if (contentProvider instanceof Workspace.UISourceCode) {
784 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); 805 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider );
785 if (!uiSourceCode.project().canSetFileContent()) 806 if (!uiSourceCode.project().canSetFileContent())
786 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); 807 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true));
787 } 808 }
788 } 809 }
789 }; 810 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698