From c3ee5afc0638f010c4ba304e9433d6e1c7c483dd Mon Sep 17 00:00:00 2001 From: Dean Sofer Date: Sat, 1 Aug 2015 20:49:43 -0700 Subject: [PATCH] Prototyping new atomic searching instead of prefixes --- src/patterns/repoActions.js | 44 +++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/patterns/repoActions.js b/src/patterns/repoActions.js index aeadc90..7aaac71 100644 --- a/src/patterns/repoActions.js +++ b/src/patterns/repoActions.js @@ -340,22 +340,58 @@ if (!repoName) return; chrome.history.search({ text: 'https://github.com/ ' + repoName }, function(results) { - var historySuggestions = []; + var suggestions = []; var found = {}; results = results.forEach(function(result){ var url = result.url.match(/https:\/\/github\.com\/(\w+\/\w+)/i); - if (url[1] && !found[url[1]]) { + if (url && url[1] && !found[url[1]]) { found[url[1]] = true; - historySuggestions.push({ content: url[1], description: result.title }); + suggestions.push({ content: url[1], description: result.title }); }; }); - defer.resolve(historySuggestions); + defer.resolve(suggestions); }); return [{ description: 'Searching Browsing History...', content: '' }, defer]; }, decide: function (args) { return omni.urls.search + args[0].substr(1); } + }, + "atomic": { + pattern: /\S*/, + suggest: function(args) { + var repoName = args[0].toLowerCase(), + myRepos = [{content:'', description: 'Searching Repos...'}]; + + // OWNED + myRepos = myRepos.concat(filterRepos(omni.caches.my.repos, repoName, true)); + // STARRED + myRepos = myRepos.concat(filterRepos(omni.caches.starred, repoName, true)); + + // HISTORY + if (repoName) { + var defer = Defer(); + chrome.history.search({ text: 'https://github.com/ ' + repoName }, function(results) { + var suggestions = []; + var found = {}; + results = results.forEach(function(result){ + var url = result.url.match(/https:\/\/github\.com\/(\w+\/\w+)/i); + if (url && url[1] && !found[url[1]]) { + found[url[1]] = true; + suggestions.push({ content: url[1], description: result.title }); + }; + }); + myRepos.pop(); + defer.resolve(myRepos.concat(suggestions)); + }); + myRepos.push(defer); + } + // RETURNED + return myRepos; + }, + decide: function(args) { + return; + } } });