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

Unified Diff: chrome/browser/resources/md_history/history_item.js

Issue 1643693003: MD History: Implement search functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch_to_be_uploaded
Patch Set: Fix time-gap-separator insertion. Created 4 years, 10 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: chrome/browser/resources/md_history/history_item.js
diff --git a/chrome/browser/resources/md_history/history_item.js b/chrome/browser/resources/md_history/history_item.js
index 4b988cd6437cc1bde1cccea3e4f79947977d9da0..aa27c63214d38e4fd4d11e32862016f1b03beed0 100644
--- a/chrome/browser/resources/md_history/history_item.js
+++ b/chrome/browser/resources/md_history/history_item.js
@@ -13,7 +13,8 @@ Polymer({
websiteTitle_: {
type: String,
- value: ''
+ value: '',
+ observer: 'setSearchedTextToBold_'
},
// Domain is the website text shown on the history-item next to the title.
@@ -47,6 +48,13 @@ Polymer({
value: 0
},
+ // Search term used in the chrome.send to obtain this history-item.
+ searchTerm: {
+ type: String,
+ value: '',
+ observer: 'setSearchedTextToBold_'
+ },
+
selected: {
type: Boolean,
value: false,
@@ -92,6 +100,48 @@ Polymer({
e.stopPropagation();
},
+ /**
+ * If the results shown are search results set the search term to be bold
+ * where it is displayed in the history-item title.
+ * @private
+ */
+ setSearchedTextToBold_: function() {
+ var i = 0;
+ var title = this.$.title;
+
+ if (this.searchTerm == '' || this.searchTerm == null) {
+ title.textContent = this.websiteTitle_;
+ return;
+ }
+
+ var re = new RegExp(this.quoteString_(this.searchTerm), 'gim');
+ var match;
+ title.textContent = '';
+ while (match = re.exec(this.websiteTitle_)) {
+ if (match.index > i)
+ title.appendChild(document.createTextNode(
+ this.websiteTitle_.slice(i, match.index)));
+ i = re.lastIndex;
+ // Mark the highlighted text in bold.
+ var b = document.createElement('b');
+ b.textContent = this.websiteTitle_.substring(match.index, i);
+ title.appendChild(b);
+ }
+ if (i < this.websiteTitle_.length)
+ title.appendChild(document.createTextNode(this.websiteTitle_.slice(i)));
+ },
+
+ /**
+ * Quote a string so it can be used in a regular expression.
+ * @param {string} searchTerm The source string.
+ * @return {string} The escaped string.
+ * @private
+ */
+ quoteString_: function(searchTerm) {
+ return searchTerm.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g,
+ '\\$1');
+ },
+
selectionNotAllowed_: function() {
return !loadTimeData.getBoolean('allowDeletingHistory');
}

Powered by Google App Engine
This is Rietveld 408576698