aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-08-30 21:06:31 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-09-02 10:14:30 +0900
commit3e2820a6b4404568a36ebe279a97bb0bf2617c74 (patch)
treed4ff760418a096175416abe40a01f02fd74e430c
parented992e06748eb125c3cda04f18fe2e60102c4a19 (diff)
throw error on multiple buffer matched
-rw-r--r--src/background/tabs.js18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/background/tabs.js b/src/background/tabs.js
index 201fa73..617909e 100644
--- a/src/background/tabs.js
+++ b/src/background/tabs.js
@@ -33,19 +33,17 @@ const selectAt = (index) => {
const selectByKeyword = (keyword) => {
chrome.tabs.query({ currentWindow: true }, (tabs) => {
- let tab = tabs.find((tab) => tab.url.includes(keyword))
- if (tab) {
- chrome.tabs.update(tab.id, { active: true });
- return;
- }
+ let matched = tabs.filter((t) => {
+ return t.url.includes(keyword) || t.title.includes(keyword)
+ })
- tab = tabs.find((tab) => tab.title.includes(keyword))
- if (tab) {
- chrome.tabs.update(tab.id, { active: true });
- return;
+ if (matched.length == 0) {
+ throw new RangeError('No matching buffer for ' + keyword);
+ } else if (matched.length >= 2) {
+ throw new RangeError('More than one match for ' + keyword);
}
- throw new RangeError('No matching buffer for ' + keyword);
+ chrome.tabs.update(matched[0].id, { active: true });
})
}