throw error on multiple buffer matched

jh-changes
Shin'ya Ueoka 7 years ago
parent ed992e0674
commit 3e2820a6b4
  1. 18
      src/background/tabs.js

@ -33,19 +33,17 @@ const selectAt = (index) => {
const selectByKeyword = (keyword) => { const selectByKeyword = (keyword) => {
chrome.tabs.query({ currentWindow: true }, (tabs) => { chrome.tabs.query({ currentWindow: true }, (tabs) => {
let tab = tabs.find((tab) => tab.url.includes(keyword)) let matched = tabs.filter((t) => {
if (tab) { return t.url.includes(keyword) || t.title.includes(keyword)
chrome.tabs.update(tab.id, { active: true }); })
return;
}
tab = tabs.find((tab) => tab.title.includes(keyword)) if (matched.length == 0) {
if (tab) { throw new RangeError('No matching buffer for ' + keyword);
chrome.tabs.update(tab.id, { active: true }); } else if (matched.length >= 2) {
return; 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 });
}) })
} }