From e286aab3d7af50494f78d6a470ed20c5c8cfc59b Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 30 May 2018 21:38:01 +0900 Subject: [PATCH 1/3] Check title null --- src/background/shared/tabs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/background/shared/tabs.js b/src/background/shared/tabs.js index d09f676..8135d0e 100644 --- a/src/background/shared/tabs.js +++ b/src/background/shared/tabs.js @@ -87,7 +87,7 @@ const selectAt = (index) => { 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); + return t.url.includes(keyword) || t.title && t.title.includes(keyword); }); if (matched.length === 0) { From 68fa80e1a300c3fe9504d51e166b64964189736d Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 30 May 2018 22:05:12 +0900 Subject: [PATCH 2/3] Use queryByKeyword for tab operations --- src/background/shared/completions/tabs.js | 12 ++---- src/background/shared/tabs.js | 48 +++++++++++------------ 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/background/shared/completions/tabs.js b/src/background/shared/completions/tabs.js index 8c0f1f9..bdb2741 100644 --- a/src/background/shared/completions/tabs.js +++ b/src/background/shared/completions/tabs.js @@ -1,12 +1,8 @@ +import * as tabs from '../tabs'; + const getCompletions = (keyword, excludePinned) => { - return browser.tabs.query({ currentWindow: true }).then((tabs) => { - let matched = tabs.filter((t) => { - return t.url.includes(keyword) || t.title && t.title.includes(keyword); - }).filter((t) => { - return !(excludePinned && t.pinned); - }); - return matched; - }); + return tabs.queryByKeyword(keyword, excludePinned); }; + export { getCompletions }; diff --git a/src/background/shared/tabs.js b/src/background/shared/tabs.js index 8135d0e..6b171a3 100644 --- a/src/background/shared/tabs.js +++ b/src/background/shared/tabs.js @@ -12,37 +12,38 @@ const closeTabForce = (id) => { return browser.tabs.remove(id); }; -const closeTabByKeywords = (keyword) => { +const queryByKeyword = (keyword, excludePinned = false) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => { - let matched = tabs.filter((t) => { - return t.url.includes(keyword) || t.title.includes(keyword); - }).filter(t => !t.pinned); + return tabs.filter((t) => { + return t.url.includes(keyword) || t.title && t.title.includes(keyword); + }).filter((t) => { + return !(excludePinned && t.pinned); + }); + }); +}; - if (matched.length === 0) { +const closeTabByKeywords = (keyword) => { + return queryByKeyword(keyword, false).then((tabs) => { + if (tabs.length === 0) { throw new Error('No matching buffer for ' + keyword); - } else if (matched.length > 1) { + } else if (tabs.length > 1) { throw new Error('More than one match for ' + keyword); } - browser.tabs.remove(matched[0].id); + browser.tabs.remove(tabs[0].id); }); }; const closeTabByKeywordsForce = (keyword) => { - return browser.tabs.query({ currentWindow: true }).then((tabs) => { - let matched = tabs.filter((t) => { - return t.url.includes(keyword) || t.title.includes(keyword); - }); - - if (matched.length === 0) { + return queryByKeyword(keyword, true).then((tabs) => { + if (tabs.length === 0) { throw new Error('No matching buffer for ' + keyword); - } else if (matched.length > 1) { + } else if (tabs.length > 1) { throw new Error('More than one match for ' + keyword); } - browser.tabs.remove(matched[0].id); + browser.tabs.remove(tabs[0].id); }); }; - const closeTabsByKeywords = (keyword) => { tabCompletions.getCompletions(keyword).then((tabs) => { let tabs2 = tabs.filter(tab => !tab.pinned); @@ -85,20 +86,16 @@ const selectAt = (index) => { }; const selectByKeyword = (current, keyword) => { - return browser.tabs.query({ currentWindow: true }).then((tabs) => { - let matched = tabs.filter((t) => { - return t.url.includes(keyword) || t.title && t.title.includes(keyword); - }); - - if (matched.length === 0) { + return queryByKeyword(keyword).then((tabs) => { + if (tabs.length === 0) { throw new RangeError('No matching buffer for ' + keyword); } - for (let tab of matched) { + for (let tab of tabs) { if (tab.index > current.index) { return browser.tabs.update(tab.id, { active: true }); } } - return browser.tabs.update(matched[0].id, { active: true }); + return browser.tabs.update(tabs[0].id, { active: true }); }); }; @@ -165,7 +162,8 @@ const duplicate = (id) => { }; export { - closeTab, closeTabForce, closeTabByKeywords, closeTabByKeywordsForce, + closeTab, closeTabForce, + queryByKeyword, closeTabByKeywords, closeTabByKeywordsForce, closeTabsByKeywords, closeTabsByKeywordsForce, reopenTab, selectAt, selectByKeyword, selectPrevTab, selectNextTab, selectFirstTab, From 0f3ad23085c8e2fd7c350590b3ee87cac6ade945 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 30 May 2018 22:10:39 +0900 Subject: [PATCH 3/3] Ignore cases for tab filtering --- src/background/shared/tabs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/background/shared/tabs.js b/src/background/shared/tabs.js index 6b171a3..62e26ac 100644 --- a/src/background/shared/tabs.js +++ b/src/background/shared/tabs.js @@ -15,7 +15,8 @@ const closeTabForce = (id) => { const queryByKeyword = (keyword, excludePinned = false) => { return browser.tabs.query({ currentWindow: true }).then((tabs) => { return tabs.filter((t) => { - return t.url.includes(keyword) || t.title && t.title.includes(keyword); + return t.url.toLowerCase().includes(keyword.toLowerCase()) || + t.title && t.title.toLowerCase().includes(keyword.toLowerCase()); }).filter((t) => { return !(excludePinned && t.pinned); });