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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/workspace/SearchConfig.js

Issue 2660853002: DevTools: fix search across all files in case of "file:" prefix (Closed)
Patch Set: use \s instead of space Created 3 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/sources/search-config-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @implements {Workspace.ProjectSearchConfig} 5 * @implements {Workspace.ProjectSearchConfig}
6 * @unrestricted 6 * @unrestricted
7 */ 7 */
8 Workspace.SearchConfig = class { 8 Workspace.SearchConfig = class {
9 /** 9 /**
10 * @param {string} query 10 * @param {string} query
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 /** 53 /**
54 * @return {{query: string, ignoreCase: boolean, isRegex: boolean}} 54 * @return {{query: string, ignoreCase: boolean, isRegex: boolean}}
55 */ 55 */
56 toPlainObject() { 56 toPlainObject() {
57 return {query: this.query(), ignoreCase: this.ignoreCase(), isRegex: this.is Regex()}; 57 return {query: this.query(), ignoreCase: this.ignoreCase(), isRegex: this.is Regex()};
58 } 58 }
59 59
60 _parse() { 60 _parse() {
61 var filePattern = 61 // Inside double quotes: any symbol except double quote and backslash or any symbol escaped with a backslash.
62 '-?f(ile)?:(([^\\\\ ]|\\\\.)+)'; // After file: prefix: any symbol exce pt space and backslash or any symbol escaped with a backslash. 62 var quotedPattern = /"([^\\"]|\\.)+"/;
63 var quotedPattern = 63 // A word is a sequence of any symbols except space and backslash or any sym bols escaped with a backslash, that does not start with file:.
64 '"(([^\\\\"]|\\\\.)+)"'; // Inside double quotes: any symbol except dou ble quote and backslash or any symbol escaped with a backslash. 64 var unquotedWordPattern = /(\s*(?!-?f(ile)?:)[^\\ ]|\\.)+/;
65 var unquotedPattern = unquotedWordPattern.source + '(\\s+' + unquotedWordPat tern.source + ')*';
65 66
66 // A word is a sequence of any symbols except space and backslash or any sym bols escaped with a backslash, that does not start with file:.
67 var unquotedWordPattern = '(\\s*(?!-?f(ile)?:)[^\\\\ ]|\\\\.)+';
68 var unquotedPattern =
69 unquotedWordPattern + '( +' + unquotedWordPattern + ')*'; // A word or several words separated by space(s).
70 67
71 var pattern = '(' + filePattern + ')|(' + quotedPattern + ')|(' + unquotedPa ttern + ')'; 68 var pattern = [
69 '(\\s*' + Workspace.SearchConfig.FilePatternRegex.source + '\\s*)',
70 '(' + quotedPattern.source + ')',
71 '(' + unquotedPattern + ')',
72 ].join('|');
72 var regexp = new RegExp(pattern, 'g'); 73 var regexp = new RegExp(pattern, 'g');
73 var queryParts = this._query.match(regexp) || []; 74 var queryParts = this._query.match(regexp) || [];
74
75 /** 75 /**
76 * @type {!Array.<!Workspace.SearchConfig.QueryTerm>} 76 * @type {!Array.<!Workspace.SearchConfig.QueryTerm>}
77 */ 77 */
78 this._fileQueries = []; 78 this._fileQueries = [];
79 79
80 /** 80 /**
81 * @type {!Array.<string>} 81 * @type {!Array.<string>}
82 */ 82 */
83 this._queries = []; 83 this._queries = [];
84 84
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 _parseQuotedQuery(query) { 139 _parseQuotedQuery(query) {
140 return query.substring(1, query.length - 1).replace(/\\(.)/g, '$1'); 140 return query.substring(1, query.length - 1).replace(/\\(.)/g, '$1');
141 } 141 }
142 142
143 /** 143 /**
144 * @param {string} query 144 * @param {string} query
145 * @return {?Workspace.SearchConfig.QueryTerm} 145 * @return {?Workspace.SearchConfig.QueryTerm}
146 */ 146 */
147 _parseFileQuery(query) { 147 _parseFileQuery(query) {
148 var match = query.match(/^(-)?f(ile)?:/); 148 var match = query.match(Workspace.SearchConfig.FilePatternRegex);
149 if (!match) 149 if (!match)
150 return null; 150 return null;
151 var isNegative = !!match[1]; 151 var isNegative = !!match[1];
152 query = query.substr(match[0].length); 152 query = match[3];
153 var result = ''; 153 var result = '';
154 for (var i = 0; i < query.length; ++i) { 154 for (var i = 0; i < query.length; ++i) {
155 var char = query[i]; 155 var char = query[i];
156 if (char === '*') { 156 if (char === '*') {
157 result += '.*'; 157 result += '.*';
158 } else if (char === '\\') { 158 } else if (char === '\\') {
159 ++i; 159 ++i;
160 var nextChar = query[i]; 160 var nextChar = query[i];
161 if (nextChar === ' ') 161 if (nextChar === ' ')
162 result += ' '; 162 result += ' ';
163 } else { 163 } else {
164 if (String.regexSpecialCharacters().indexOf(query.charAt(i)) !== -1) 164 if (String.regexSpecialCharacters().indexOf(query.charAt(i)) !== -1)
165 result += '\\'; 165 result += '\\';
166 result += query.charAt(i); 166 result += query.charAt(i);
167 } 167 }
168 } 168 }
169 return new Workspace.SearchConfig.QueryTerm(result, isNegative); 169 return new Workspace.SearchConfig.QueryTerm(result, isNegative);
170 } 170 }
171 }; 171 };
172 172
173 // After file: prefix: any symbol except space and backslash or any symbol escap ed with a backslash.
174 Workspace.SearchConfig.FilePatternRegex = /(-)?f(ile)?:((?:[^\\ ]|\\.)+)/;
175
173 /** @typedef {!{regex: !RegExp, isNegative: boolean}} */ 176 /** @typedef {!{regex: !RegExp, isNegative: boolean}} */
174 Workspace.SearchConfig.RegexQuery; 177 Workspace.SearchConfig.RegexQuery;
175 178
176 179
177 /** 180 /**
178 * @unrestricted 181 * @unrestricted
179 */ 182 */
180 Workspace.SearchConfig.QueryTerm = class { 183 Workspace.SearchConfig.QueryTerm = class {
181 /** 184 /**
182 * @param {string} text 185 * @param {string} text
183 * @param {boolean} isNegative 186 * @param {boolean} isNegative
184 */ 187 */
185 constructor(text, isNegative) { 188 constructor(text, isNegative) {
186 this.text = text; 189 this.text = text;
187 this.isNegative = isNegative; 190 this.isNegative = isNegative;
188 } 191 }
189 }; 192 };
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/sources/search-config-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698