Index: third_party/WebKit/Source/devtools/front_end/platform/utilities.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/platform/utilities.js b/third_party/WebKit/Source/devtools/front_end/platform/utilities.js |
index cea60fb5c5a31d684ae2ce86d5b13d69ade5b0a3..ce085d2368f6ea477757a3499b83fd01c4af3fbd 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/platform/utilities.js |
+++ b/third_party/WebKit/Source/devtools/front_end/platform/utilities.js |
@@ -160,8 +160,19 @@ String.prototype.collapseWhitespace = function() { |
* @return {string} |
*/ |
String.prototype.trimMiddle = function(maxLength) { |
- if (this.length <= maxLength) |
+ var indices = this.trimMiddleIndices(maxLength); |
+ if (indices === null) |
return String(this); |
+ return this.substr(0, indices[0]) + '\u2026' + this.substr(indices[1], this.length - indices[1]); |
+}; |
+ |
+/** |
+ * @param {number} maxLength |
+ * @return {?Array<number>} |
+ */ |
+String.prototype.trimMiddleIndices = function(maxLength) { |
lushnikov
2017/04/17 17:57:40
Let's not introduce this method - it would be hard
luoe
2017/04/17 22:15:07
Done.
|
+ if (this.length <= maxLength) |
+ return null; |
var leftHalf = maxLength >> 1; |
var rightHalf = maxLength - leftHalf - 1; |
if (this.codePointAt(this.length - rightHalf - 1) >= 0x10000) { |
lushnikov
2017/04/17 17:57:40
Wow, something is going on here! Do you know why w
luoe
2017/04/17 22:15:07
Emoji characters have length > 1, and we do not br
|
@@ -170,7 +181,7 @@ String.prototype.trimMiddle = function(maxLength) { |
} |
if (leftHalf > 0 && this.codePointAt(leftHalf - 1) >= 0x10000) |
--leftHalf; |
- return this.substr(0, leftHalf) + '\u2026' + this.substr(this.length - rightHalf, rightHalf); |
+ return [leftHalf, this.length - rightHalf]; |
}; |
/** |