diff options
| author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-05 19:37:52 +0900 | 
|---|---|---|
| committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-05 19:37:52 +0900 | 
| commit | 2cbdc483b7ecdee0627daaf934e6010e77d68a77 (patch) | |
| tree | 6f8b8667f835bfb7e778cc571d8869cb5903a08a /src/background/tabs.js | |
| parent | 8cabd68b927fe7022efa11dee082aafe8c2d4f30 (diff) | |
| parent | c507f7febf0d8827dafcc6fd543678af447c056c (diff) | |
Merge branch 'buffer-completion'
Diffstat (limited to 'src/background/tabs.js')
| -rw-r--r-- | src/background/tabs.js | 21 | 
1 files changed, 16 insertions, 5 deletions
diff --git a/src/background/tabs.js b/src/background/tabs.js index efecdc4..111bbd9 100644 --- a/src/background/tabs.js +++ b/src/background/tabs.js @@ -31,7 +31,7 @@ const selectAt = (index) => {    });  }; -const selectByKeyword = (keyword) => { +const selectByKeyword = (current, keyword) => {    return browser.tabs.query({ currentWindow: true }).then((tabs) => {      let matched = tabs.filter((t) => {        return t.url.includes(keyword) || t.title.includes(keyword) @@ -39,14 +39,25 @@ const selectByKeyword = (keyword) => {      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);      } - +    for (let tab of matched) { +      if (tab.index > current.index) { +        return browser.tabs.update(tab.id, { active: true }); +      } +    }      return browser.tabs.update(matched[0].id, { active: true });    });  } +const getCompletions = (keyword) => { +  return browser.tabs.query({ currentWindow: true }).then((tabs) => { +    let matched = tabs.filter((t) => { +      return t.url.includes(keyword) || t.title.includes(keyword) +    }) +    return matched; +  }); +}; +  const selectPrevTab = (current, count) => {    return browser.tabs.query({ currentWindow: true }, (tabs) => {      if (tabs.length < 2) { @@ -76,4 +87,4 @@ const reload = (current, cache) => {    );  }; -export { closeTab, reopenTab, selectAt, selectByKeyword, selectNextTab, selectPrevTab, reload }; +export { closeTab, reopenTab, selectAt, selectByKeyword, getCompletions, selectPrevTab, selectNextTab, reload };  | 
