Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ====in AdvanceSearchController.js====
- WebInspector.SearchConfig = function(query, ignoreCase, isRegex)
- {
- this.query = query;
- this.ignoreCase = ignoreCase;
- this.isRegex = isRegex;
- this._queryConfig = this._parseSearchQuery();
- }
- WebInspector.SearchConfig.prototype = {
- _parseSearchQuery: function()
- {
- if (this.query === "")
- return;
- var queryConfig = {};
- function isSoureCodeSelectorToken(token)
- {
- var matches = /^file:(.*)/gi.exec(token);
- return matches && matches[1];
- }
- function isQuotedToken(query)
- {
- return query[0] === "\"" ? true : false;
- }
- function buildQueryTokens(queryString)
- {
- var tokens = queryString.match(/([^\s]*\"([^\\"]|\\\\|\\")*\"[^\s]*)|([^\s]+)/gi);
- /*
- taking it as an array as we need to check each query string's presence in all qualified source code.
- I am not very sure of how to properly apply "and" within regex.
- */
- var simpleStringPattern = [];
- var quotedStringPattern = [];
- var sourceCodeSelectorPattern = [];
- for(var i=0; i < tokens.length ; ++i) {
- if (isQuotedToken(tokens[i]))
- quotedStringPattern.push(tokens[i].replace(/^"|"$/g, ""));
- else if (isSoureCodeSelectorToken(tokens[i]))
- sourceCodeSelectorPattern.push(tokens[i].split(":")[1]);
- else
- simpleStringPattern.push(tokens[i]);
- }
- if (sourceCodeSelectorPattern.length) {
- queryConfig.sourceCodeSelectors = sourceCodeSelectorPattern;
- queryConfig.searchQueryStrings = quotedStringPattern.concat(simpleStringPattern);
- /* having a state to check if source code selector(file:xx) is mentioned */
- queryConfig.sourceCodeSelectorQueryState = true;
- } else
- queryConfig.sourceCodeSelectorQueryState = false;
- }
- buildQueryTokens(this.query);
- return queryConfig;
- },
- get queries()token file:js
- {
- return this._queryConfig.searchQueryStrings;
- },
- get sourceCodeSelectors()
- {
- return this._queryConfig.sourceCodeSelectors;
- },
- get isSourceCodeSelectorEnabled()
- {
- return this._queryConfig.sourceCodeSelectorQueryState;
- },
- isSourceCodeSelectorScript : function(url)
- {
- for (var i = 0; i < this.sourceCodeSelectors.length ; ++i ) {
- var regex = new RegExp(this.sourceCodeSelectors[i],"gi");
- if (!regex.test(url))
- return false;
- }
- return true;
- }
- }
- ====in ScriptSearchScope.js====
- performSearch: function(searchConfig, searchResultCallback, searchFinishedCallback)
- {
- this.stopSearch();
- var uiSourceCodes = this._sortedUISourceCodes();
- var uiSourceCodeIndex = 0;
- var searchQueryIndex = 0;
- var searchResultsConfig = {searchMatches:[], queryCount:0};
- function filterOutContentScripts(uiSourceCode)
- {
- return !uiSourceCode.isContentScript;
- }
- function filterOutSourceCodeSelectorScripts(uiSourceCode)
- {
- return searchConfig.isSourceCodeSelectorScript(uiSourceCode.contentURL());
- }
- if (!WebInspector.settings.searchInContentScripts.get())
- uiSourceCodes = uiSourceCodes.filter(filterOutContentScripts);
- if (searchConfig.isSourceCodeSelectorEnabled)
- uiSourceCodes = uiSourceCodes.filter(filterOutSourceCodeSelectorScripts);
- function continueSearch()
- {
- // FIXME: Enable support for counting matches for incremental search.
- // FIXME: Enable support for bounding search results/matches number to keep inspector responsive.
- function updateIndexes()
- {
- uiSourceCodeIndex++;
- searchQueryIndex = 0;
- searchResultsConfig = {searchMatches:[], queryCount:0};
- }
- /*
- I tried combining all as a string. ex for "file:js foo bar abc"
- regex = "(?=.*foo)(?=.*bar)(?=.*abc)"
- but searchInContect was not returning proper results.
- Am not very sure of applying "and" within regex.
- */
- function searchQueryInSelectorSourceCode(uiSourceCode)
- {
- if (searchQueryIndex < searchConfig.queries.length) {
- uiSourceCode.searchInContent(searchConfig.queries[searchQueryIndex], !searchConfig.ignoreCase, true,
- searchCallbackWrapper.bind(this, this._searchId, uiSourceCode));
- } else {
- if (searchResultsConfig.queryCount == searchConfig.queries.length) {
- var searchResult = new WebInspector.FileBasedSearchResultsPane.SearchResult(uiSourceCode, searchResultsConfig.searchMatches);
- searchResultCallback(searchResult);
- }
- updateIndexes();
- continueSearch.call(this);
- }
- }
- if (uiSourceCodeIndex < uiSourceCodes.length) {
- var uiSourceCode = uiSourceCodes[uiSourceCodeIndex];
- if (searchConfig.isSourceCodeSelectorEnabled)
- searchQueryInSelectorSourceCode(uiSourceCode);
- else
- uiSourceCode.searchInContent(searchConfig.query, !searchConfig.ignoreCase, searchConfig.isRegex,
- searchCallbackWrapper.bind(this, this._searchId, uiSourceCode));
- } else
- searchFinishedCallback(true);
- }
- function searchCallbackWrapper(searchId, uiSourceCode, searchMatches)
- {
- if (searchId !== this._searchId) {
- searchFinishedCallback(false);
- return;
- }
- if (searchConfig.isSourceCodeSelectorEnabled) {
- searchQueryIndex++;
- if (searchMatches.length) {
- searchResultsConfig.searchMatches = searchResultsConfig.searchMatches.concat(searchMatches);
- searchResultsConfig.queryCount++;
- }
- }
- else if (!searchConfig.isSourceCodeSelectorEnabled){
- var searchResult = new WebInspector.FileBasedSearchResultsPane.SearchResult(uiSourceCode, searchMatches);
- searchResultCallback(searchResult);
- uiSourceCodeIndex++;
- }
- continueSearch.call(this);
- }
- continueSearch.call(this);
- return uiSourceCodes.length;
- },
Add Comment
Please, Sign In to add comment