Index: third_party/WebKit/Source/devtools/front_end/components/Linkifier.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/components/Linkifier.js b/third_party/WebKit/Source/devtools/front_end/components/Linkifier.js |
index 6184cc95d5d4eb1254e5cddb10c6985f96a1c68c..7d547e049c1805bceb4c58fbc18e5e817fa3fdb4 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/components/Linkifier.js |
+++ b/third_party/WebKit/Source/devtools/front_end/components/Linkifier.js |
@@ -303,13 +303,8 @@ Components.Linkifier = class { |
return; |
Components.Linkifier._bindUILocation(anchor, uiLocation); |
- var text = uiLocation.linkText(); |
- var info = Components.Linkifier._linkInfo(anchor); |
- info.originalLinkText = text; |
- text = text.replace(/([a-f0-9]{7})[a-f0-9]{13}[a-f0-9]*/g, '$1\u2026'); |
- if (this._maxLength) |
- text = text.trimMiddle(this._maxLength); |
- anchor.textContent = text; |
+ var text = uiLocation.linkText(true /* skipTrim */); |
+ Components.Linkifier._setTrimmedText(anchor, text, true /* trimHashes */, this._maxLength); |
var titleText = uiLocation.uiSourceCode.url(); |
if (typeof uiLocation.lineNumber === 'number') |
@@ -396,9 +391,7 @@ Components.Linkifier = class { |
link.title = title; |
if (href) |
link.href = href; |
- link.textContent = text; |
- if (maxLength) |
- link.textContent = link.textContent.trimMiddle(maxLength); |
+ Components.Linkifier._setTrimmedText(link, text, false /* trimHashes */, maxLength); |
link[Components.Linkifier._infoSymbol] = { |
icon: null, |
enableDecorator: false, |
@@ -408,8 +401,7 @@ Components.Linkifier = class { |
lineNumber: null, |
columnNumber: null, |
revealable: null, |
- fallback: null, |
- originalLinkText: text |
+ fallback: null |
}; |
if (!preventClick) |
link.addEventListener('click', Components.Linkifier._handleClick, false); |
@@ -419,12 +411,65 @@ Components.Linkifier = class { |
} |
/** |
- * @param {?Element} link |
- * @return {?string} |
+ * @param {!Element} link |
+ * @param {string} text |
+ * @param {boolean=} trimHashes |
+ * @param {number=} maxLength |
+ */ |
+ static _setTrimmedText(link, text, trimHashes, maxLength) { |
+ var middle = Math.floor(text.length / 2); |
+ var hiddenIndices = maxLength ? (text.trimMiddleIndices(maxLength) || [middle, middle]) : [middle, middle]; |
+ |
+ // Truncate from an earlier position if a hash pattern is starting, or a later position if a hash is ending. |
+ if (trimHashes) { |
lushnikov
2017/04/17 17:57:40
I don't quite follow what's going on here. I thoug
luoe
2017/04/17 22:15:07
That is correct. I'm trying to calculate the indi
|
+ var hashRegex = /[a-f0-9]{20,}/g; |
+ var match = hashRegex.exec(text); |
+ var visibleHashLength = 7; |
+ while (match !== null) { |
+ var hashLeftIndex = match.index + visibleHashLength; |
+ var hashRightIndex = match.index + match[0].length - visibleHashLength; |
+ if (hashLeftIndex < hiddenIndices[0]) |
+ hiddenIndices[0] = hashLeftIndex; |
+ if (hashRightIndex > hiddenIndices[1]) |
+ hiddenIndices[1] = hashRightIndex; |
+ match = hashRegex.exec(text); |
+ } |
+ } |
+ |
+ if (hiddenIndices[0] !== hiddenIndices[1]) { |
+ var leftText = text.substr(0, hiddenIndices[0]); |
+ var hiddenText = text.substr(hiddenIndices[0], hiddenIndices[1] - hiddenIndices[0]); |
+ var rightText = text.substr(hiddenIndices[1], text.length - hiddenIndices[1]); |
+ link.removeChildren(); |
+ link.createTextChild(leftText); |
+ var ellipsisSpan = link.createChild('span', 'devtools-link-ellipsis'); |
+ var ellipsisTextNode = ellipsisSpan.createTextChild('\u200B'); |
+ ellipsisTextNode[Components.Linkifier._originalNodeTextSymbol] = hiddenText; |
+ link.createTextChild(rightText); |
+ } else { |
+ link.textContent = text; |
+ } |
+ } |
+ |
+ /** |
+ * @param {!Node} node |
+ * @param {number} offset |
+ * @return {number} |
+ */ |
+ static selectionOffsetToOriginalTextOffset(node, offset) { |
lushnikov
2017/04/17 17:57:40
you don't need this method anymore - let's inline
luoe
2017/04/17 22:15:07
Done, however inlining this still feels a little s
|
+ // Selecting an ellipsis text node with offset 1 should return the full original text. |
+ var originalText = node[Components.Linkifier._originalNodeTextSymbol]; |
+ if (originalText && offset === 1) |
+ return originalText.length; |
+ return offset; |
+ } |
+ |
+ /** |
+ * @param {!Node} node |
+ * @return {string} |
*/ |
- static originalLinkText(link) { |
- var info = this._linkInfo(link); |
- return info ? info.originalLinkText : null; |
+ static originalNodeText(node) { |
lushnikov
2017/04/17 17:57:40
untruncatedNodeText
luoe
2017/04/17 22:15:07
Done.
|
+ return node[Components.Linkifier._originalNodeTextSymbol] || node.textContent; |
} |
/** |
@@ -549,6 +594,7 @@ Components.Linkifier._decorator = null; |
Components.Linkifier._sourceCodeAnchors = Symbol('Linkifier.anchors'); |
Components.Linkifier._infoSymbol = Symbol('Linkifier.info'); |
+Components.Linkifier._originalNodeTextSymbol = Symbol('Linkifier.originalNodeText'); |
/** |
* @typedef {{ |
@@ -560,8 +606,7 @@ Components.Linkifier._infoSymbol = Symbol('Linkifier.info'); |
* lineNumber: ?number, |
* columnNumber: ?number, |
* revealable: ?Object, |
- * fallback: ?Element, |
- * originalLinkText: string |
+ * fallback: ?Element |
* }} |
*/ |
Components._LinkInfo; |