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

Unified Diff: third_party/WebKit/Source/devtools/front_end/platform/utilities.js

Issue 2644753002: DevTools: untruncate links on copy (Closed)
Patch Set: reset tests with zero width space 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 side-by-side diff with in-line comments
Download patch
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];
};
/**

Powered by Google App Engine
This is Rietveld 408576698